PHP怎么合并二维数组

WBOY
Release: 2016-06-13 12:22:22
Original
1391 people have browsed it

PHP如何合并二维数组
"arr": [
                {
                    "a": "XXX"
                },
                {
                    "a": "YYY"
                }
]

这是前段print_r出来的数据
我想改成:

"arr": [
                {
                     "XXX",
                    "YYY"
                }
]

------解决思路----------------------

$s =<<< TXT<br />{"arr": [<br />                {<br />                    "a": "XXX"<br />                },<br />                {<br />                    "a": "YYY"<br />                }<br />]<br />}<br />TXT;<br /><br />$t = json_decode($s, 1);<br />array_walk($t['arr'], function(&$v) {$v = current($v);});<br />print_r($t);<br />echo json_encode($t);
Copy after login
Array<br />(<br />    [arr] => Array<br />        (<br />            [0] => XXX<br />            [1] => YYY<br />        )<br /><br />)<br />{"arr":["XXX","YYY"]}<br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!