PHP从多维数组中提取值而没有循环

I'm just wondering if it's possible to extract values from an array, in PHP, without having to loop through. Here's part of my array so you know what I mean;

Array
(
[0] => Array
    (
        [0] => 76
        [1] => Adventures of Huckleberry Finn
    )

[1] => Array
    (
        [0] => 65
        [1] => Adventures of Huckleberry Finn
    )

[2] => Array
    (
        [0] => 59
        [1] => Bookcases
    )
)

I'm after the integer [0] from each array - is there a function that can do this quicker than a foreach loop (the way I normally do this) ?

Thanks.

You eventually mean array_walk ... but this also some sort of loop? Then: the answer is no.

And I don't think that there is any quicker method (except from writing your own extension in C :-P)

Try:

array_walk($array, function(&$v) { $v = $v[0]; });

That should convert the array into the format you want.

You would probably be looking for array_walk()

$newArray = array();
$myCallback = function($key) use(&$newArray){
  $newArray[] = $key[0];
};

array_walk($myArray, $myCallback);

This would be of course if you had your array above in variable $myArray

Go for a clear loop, your fellow coders will thank you. It's probably about as fast of faster then any other solution, and clear cut code is preferable over obscure loop-dodging.

Just as an illustration: how many seconds would it take you to see what:

list($b) = call_user_func_array('array_map',array_merge(array(null),$a));

...does?

Does the trick. Don't use it.

Sure you are looking for the array_column function.

$newArray = array_column($originalArray,'0');

As said in PHP Manual, with this function you can extract, from an array of arrays, the only information you need. It is normally used with Associative arrays, but you can use a number as parameter and it will work as well.