I’m having trouble with multidimensional arrays in PHP.
I’m assuming this should be simple but, I’m having difficulty wrapping my mind around the multi-dimensions.
The array that I have looks like this:
[
['projects_users' => ['project_id' => 1]],
['projects_users' => ['project_id' => 2]],
]
I would like to somehow alter this array to look like this, where all I see is an array of the project_id:
Array
(
[0] => 1
[1] => 2
)
Or, with PHP version >= 5.3:
A third fun way, with
reset:###Performance
Out of curiosity / boredom I benchmarked the iterative / functional styles with and without
reset. I was surprised to see that test 4 was the winner in every run — I thought thatarray_maphad a bit more overhead thanforeach, but (at least in this case) these tests show otherwise! Test code is here.http://pastie.org/2183604