[英]Flattening an array in PHP
I have gone through a selection of posts here on how to flatten a PHP array, but none of them have helped me to work out how to get the array down to the level I want. 我在这里阅读了一些有关如何扁平化PHP数组的文章,但是没有一篇文章帮助我确定如何将数组降低到所需的水平。
The array is currently outputting like this: 数组当前输出如下:
array(4) { [0]=> array(1) { ["entry_id"]=> string(3) "342" } [1]=> array(1) { ["entry_id"]=> string(3) "343" } [2]=> array(1) { ["entry_id"]=> string(3) "344" } [3]=> array(1) { ["entry_id"]=> string(3) "345" } }
I would like to have it like so: 我想要这样:
array = (342,343,344,345)
I have managed to get it down to this: 我设法做到这一点:
array(4) { [0]=> string(3) "342" [1]=> string(3) "343" [2]=> string(3) "344" [3]=> string(3) "345" }
With this code: 使用此代码:
foreach($submissions as $a=>$b) {
$submissions[$a] = $b['entry_id'];
}
Thank you. 谢谢。
Have you tried something like 你尝试过类似的东西吗
foreach($submissions as $a=>$b) {
$submissions[] = $b['entry_id'];
}
Because you're giving the array key=>val and the way i understand your request is you just want the values? 因为您正在给数组key => val,而我理解您的请求的方式是您只想要这些值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.