当前位置: 代码迷 >> PHP >> PHP怎么合并二维数组
  详细解决方案

PHP怎么合并二维数组

热度:31   发布时间:2016-04-28 17:14:24.0
PHP如何合并二维数组
"arr": [
                {
                    "a": "XXX"
                },
                {
                    "a": "YYY"
                }
]

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

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

------解决思路----------------------
$s =<<< TXT
{"arr": [
                {
                    "a": "XXX"
                },
                {
                    "a": "YYY"
                }
]
}
TXT;

$t = json_decode($s, 1);
array_walk($t['arr'], function(&$v) {$v = current($v);});
print_r($t);
echo json_encode($t);
Array
(
    [arr] => Array
        (
            [0] => XXX
            [1] => YYY
        )

)
{"arr":["XXX","YYY"]}
  相关解决方案