Help with array_walk
Posted: Wed Feb 01, 2006 7:45 am
Hi,
I'm trying to make a 2-dimensional array 1-dimensional with the following code:
But it doesn't seem that passing $a1D by reference helps because the output is:
$a1D is still empty after the array walk. Is there a way to make this work?
regards tores.
I'm trying to make a 2-dimensional array 1-dimensional with the following code:
Code: Select all
/* Make array one-dimentional */
$a2D = array(array(1,2,3,4), array(5,6,7,8));
$a1D = array();
array_walk($a2D, create_function('$a2Element, $key, &$a1', '$a1 = array_merge($a1, $a2Element); print_r($a1);'), $a1D);
print_r($a1D);Code: Select all
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
)
Array
(
)regards tores.