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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With