Rumah > Artikel > pembangunan bahagian belakang > PHP怎么合并二维数组
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);
Array<br />(<br /> [arr] => Array<br /> (<br /> [0] => XXX<br /> [1] => YYY<br /> )<br /><br />)<br />{"arr":["XXX","YYY"]}<br />