数组内爆...同时忽略嵌套数组?
我环顾四周,发现很多人询问如何使用嵌套数组来内爆数组。然而,这些人通常也希望包含嵌套数组。我不想包含嵌套数组...我想扔掉嵌套数组...
这是我的数组:
[tag] => Array
(
[0] => one
[1] => two
[0_attr] => Array
(
[category] => three
[lock] => four
)
[2] => five
)
如果我内爆此数组(以逗号分隔),我希望结果为:
one, two, five
注意三和四是怎样的不包括在内。因为它们是嵌套数组,所以我不想要它。我只想要即时值。我究竟该如何完成这件事?
I have looked around and I see a lot of people asking how to implode arrays with nested arrays. However, these people usually want to include the nested array as well. I do not want to include the nested array... I want to throw out the nested array...
This is my array:
[tag] => Array
(
[0] => one
[1] => two
[0_attr] => Array
(
[category] => three
[lock] => four
)
[2] => five
)
If I implode this array, comma delimited, I want the result to be:
one, two, five
Notice how three and four are NOT included. Since they are a nested array, I don't want it. I only want immediate values. How exactly would I get this done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要迭代 $tag 中的所有值并过滤掉那些 is array
比如
我发现上面的内容有点乏味,
这是改进版本的
输出:
You would need to iterate all the values in $tag and filter out those is array
such as
I found the above is a bit tedious,
here is the improved version
output :