当前位置:Gxlcms > PHP教程 > 如何删除一维数组的key,不想用两个foreach循环出来。

如何删除一维数组的key,不想用两个foreach循环出来。

时间:2021-07-01 10:21:17 帮助过:9人阅读

1.想把二维数组变成一维,删除一维KEY的arr值,有函数吗?
2.数组代码:

  1. <code> stdClass Object
  2. (
  3. [arr] => stdClass Object
  4. (
  5. [0] => stdClass Object
  6. (
  7. [id] => 14
  8. [cid] => 221
  9. [title] => 深圳市轨道交通网络运营控制中心室内精装、玻璃幕墙工程
  10. [source] =>
  11. [count] => 0
  12. [img] => http://upload.55.cn/source/44/201606/50457731d4be5e5c1.jpg
  13. [info] =>
  14. [fee] => 0
  15. [url] => /product/detail/14.html
  16. [cate_name] => 装修工程
  17. )
  18. [1] => stdClass Object
  19. (
  20. [id] => 12
  21. [cid] => 220
  22. [title] => 南充嘉陵江1000T级泊位都京码头
  23. [source] =>
  24. [count] => 0
  25. [img] => http://upload.55.cn/source/44/201606/55557731d15a3aa42.jpg
  26. [info] =>
  27. [fee] => 0
  28. [url] => /product/detail/12.html
  29. [cate_name] => 水利电力工程
  30. )
  31. </code>

如何把arr删除?否则用两个foreach循环出来不优雅。。

回复内容:

1.想把二维数组变成一维,删除一维KEY的arr值,有函数吗?
2.数组代码:

  1. <code> stdClass Object
  2. (
  3. [arr] => stdClass Object
  4. (
  5. [0] => stdClass Object
  6. (
  7. [id] => 14
  8. [cid] => 221
  9. [title] => 深圳市轨道交通网络运营控制中心室内精装、玻璃幕墙工程
  10. [source] =>
  11. [count] => 0
  12. [img] => http://upload.55.cn/source/44/201606/50457731d4be5e5c1.jpg
  13. [info] =>
  14. [fee] => 0
  15. [url] => /product/detail/14.html
  16. [cate_name] => 装修工程
  17. )
  18. [1] => stdClass Object
  19. (
  20. [id] => 12
  21. [cid] => 220
  22. [title] => 南充嘉陵江1000T级泊位都京码头
  23. [source] =>
  24. [count] => 0
  25. [img] => http://upload.55.cn/source/44/201606/55557731d15a3aa42.jpg
  26. [info] =>
  27. [fee] => 0
  28. [url] => /product/detail/12.html
  29. [cate_name] => 水利电力工程
  30. )
  31. </code>

如何把arr删除?否则用两个foreach循环出来不优雅。。

  1. <code class="php">$resultArr = $targetArr['arr'];</code>

是我理解错了?

是对象应该是 $result->arr 的

把对象转换成数组
$a = $result['arr'];

人气教程排行