PHP从数组中删除多余的数组
这里有点脑残,我有一个看起来像这样的数组:
Array (
[0] => Array ( 'fruit' => 'orange', )
[1] => Array ( 'fruit' => 'apple', )
)
annnnnnnnd 它最终必须像这样:
Array (
[0] => 'orange'
[1] => 'apple'
)
我该怎么做?
Having a bit of a brainfart here, I've got an array that looks like this:
Array (
[0] => Array ( 'fruit' => 'orange', )
[1] => Array ( 'fruit' => 'apple', )
)
annnnnnnnd it's got to end up like this:
Array (
[0] => 'orange'
[1] => 'apple'
)
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
array_map
和array_shift
或者只是循环它:
更新:如果你总是想获取第一个值或者子数组只包含一个值,那么使用
array_shift
会更好......如果你有更复杂的结构,例如更多子数组中的元素,那么您基本上想要展平数组 。
You can use
array_map
andarray_shift
or just loop over it:
Update: Using
array_shift
is much better if you always want to get the first value or if the subarrays contain only one value anyway...If you have a more complicated structure, e.g. more elements in the subarrays, then you basically want to flatten your array.
如果密钥并不总是相同(即,如果它不总是水果),您可以这样做:
If the key isn't always the same (i.e. if it isn't always fruit), you could do this: