首页 >后端开发 >php教程 >如何删除一维数组的key,不想用两个foreach循环出来。

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

WBOY
WBOY原创
2016-07-06 13:52:041071浏览

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

<code> stdClass Object
(
    [arr] => stdClass Object
        (
            [0] => stdClass Object
                (
                    [id] => 14
                    [cid] => 221
                    [title] => 深圳市轨道交通网络运营控制中心室内精装、玻璃幕墙工程
                    [source] => 
                    [count] => 0
                    [img] => http://upload.55.cn/source/44/201606/50457731d4be5e5c1.jpg
                    [info] => 
                    [fee] => 0
                    [url] => /product/detail/14.html
                    [cate_name] => 装修工程
                )

            [1] => stdClass Object
                (
                    [id] => 12
                    [cid] => 220
                    [title] => 南充嘉陵江1000T级泊位都京码头
                    [source] => 
                    [count] => 0
                    [img] => http://upload.55.cn/source/44/201606/55557731d15a3aa42.jpg
                    [info] => 
                    [fee] => 0
                    [url] => /product/detail/12.html
                    [cate_name] => 水利电力工程
                )
</code>

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

回复内容:

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

<code> stdClass Object
(
    [arr] => stdClass Object
        (
            [0] => stdClass Object
                (
                    [id] => 14
                    [cid] => 221
                    [title] => 深圳市轨道交通网络运营控制中心室内精装、玻璃幕墙工程
                    [source] => 
                    [count] => 0
                    [img] => http://upload.55.cn/source/44/201606/50457731d4be5e5c1.jpg
                    [info] => 
                    [fee] => 0
                    [url] => /product/detail/14.html
                    [cate_name] => 装修工程
                )

            [1] => stdClass Object
                (
                    [id] => 12
                    [cid] => 220
                    [title] => 南充嘉陵江1000T级泊位都京码头
                    [source] => 
                    [count] => 0
                    [img] => http://upload.55.cn/source/44/201606/55557731d15a3aa42.jpg
                    [info] => 
                    [fee] => 0
                    [url] => /product/detail/12.html
                    [cate_name] => 水利电力工程
                )
</code>

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

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

是我理解错了?

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

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn