我有一個數組分層陣列轉換爲平板陣列
$array = array(
array(1,2,3),
array('bob','bill'),
array(4,5,6,7)
//can have between 0 and 5 "rows"
);
我想轉換到一個數組,看起來像這樣...
[1,bob,4, 1, bob, 5, 1, bob, 6, 1, bob, 7, 1, bill, 4 .... 3, bill, 7]
我想寫一個遞歸功能爲這看起來像...
function GetValues($array, $rowIndex, $valIndex, $values)
{
if(!isset($array[$rowIndex]))
{
return $values;
}
if(!isset($array[$rowIndex][$valIndex]))
{
return GetValues($array,$rowIndex+1, 0, $values);
}
$values[] = $array[$rowIndex][$valIndex];
return GetValues($array,$rowIndex, $valIndex+1, $values);
}
剛剛結束了正常迭代數組(打印1,2,3,bob,bill,4,5,6, 7)
參見:http://stackoverflow.com/q/797251/3933332 – Rizier123
@ Rizier123也需要這並不什麼 – EyeOfTheHawks
'$ flatArray = call_user_func_array('array_merge',$ array);' – splash58