PHP从多维数组中提取值而没有循环 [英] PHP extract values from multidimensional array without a loop
问题描述
我只是想知道是否有可能在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
)
)
我在每个数组的整数[0]之后-是否有一个函数可以比foreach循环更快地执行此操作(我通常这样做的方式)?
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) ?
谢谢.
推荐答案
确定要查找 array_column 函数.
$newArray = array_column($originalArray,'0');
正如PHP手册中所述,使用此功能,您可以从数组数组中提取所需的唯一信息.通常与关联数组一起使用,但是您可以使用数字作为参数,并且也可以使用.
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.
这篇关于PHP从多维数组中提取值而没有循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!