我有一个数组,每个数组包含4个数组。如何在PHP中压扁数组?
array(4) {
[0]=>
array(1) {
["email"]=>
string(19) "[email protected]"
}
[1]=>
array(1) {
["email"]=>
string(19) "[email protected]"
}
[2]=>
array(1) {
["email"]=>
string(19) "[email protected]"
}
[3]=>
array(1) {
["email"]=>
string(19) "[email protected]"
}
}
什么是最好的(=最短,PHP本身的首选功能)的方式实现平坦化阵列,使其只包含电子邮件地址作为值:
array(4) {
[0]=>
string(19) "[email protected]"
[1]=>
string(19) "[email protected]"
[2]=>
string(19) "[email protected]"
[3]=>
string(19) "[email protected]"
}
或者如果你没有PHP 5.5,你可以使用官方函数 – Populus
的作者'array_column'的https://github.com/ramsey/array_column的用户空间实现,这正是我所需要的。谢谢! –
其中一天,我需要学习array_map ... – Mike