How can I get an array of values from an associative array ?
Associate array Example:
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
[2] => Array
(
[0] => 7
)
)
Desired Output
Array
(1,2,3,4,5,6,7)
Not sure it’ll suit you, as it’s PHP >= 5.3 only, but here’s a possible solution, using
array_walk_recursiveand a closure (see Anonymous functions) :And the result :
Basicaly, the closure is the only way I got this to work : it’s used to import the
$resultvariable, by reference, into the anonymous function.And, just to post it, the only I got this working for PHP 5.2 (i.e. not using a closure) is with this :
Which works too — but raises a warning :
Unfortunatly, I didn’t find a way of getting this to work without passing
$resultby reference at call-time 🙁(Maybe someone else has an idea, about how to do that ?)