如何向json对象追加一个新的数组
展开全部
<?php
$arr = json_decode('[{"name":"caocao","sex":"男"}]', true);
$tmp = json_decode('{"name":"diaochan","sex":"女"}', true);
array_push($arr, $tmp);
print_r($arr);
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
输出:
[{"name":"caocao","sex":"男"},{"name":"diaochan","sex":"女"}]
$arr = json_decode('[{"name":"caocao","sex":"男"}]', true);
$tmp = json_decode('{"name":"diaochan","sex":"女"}', true);
array_push($arr, $tmp);
print_r($arr);
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
输出:
[{"name":"caocao","sex":"男"},{"name":"diaochan","sex":"女"}]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询