Php 如何从json响应中删除密钥?
我有一个集合Php 如何从json响应中删除密钥?,php,laravel,laravel-4,Php,Laravel,Laravel 4,我有一个集合$tree,它正在通过Response::json()转换为json。该键将自动设置为第一个对象的id。有没有办法消除这种情况,或者通过以下方式进行重组: 'data': [ { first object }, { second object} ] 它目前的答复是: {"1":{"id":"1","parent_id":null,"lft":"1","rgt":"8","depth":"0"... 我想要的是: {'data':[{"id":"1","parent
$tree
,它正在通过Response::json()
转换为json。该键将自动设置为第一个对象的id
。有没有办法消除这种情况,或者通过以下方式进行重组:
'data': [
{ first object },
{ second object}
]
它目前的答复是:
{"1":{"id":"1","parent_id":null,"lft":"1","rgt":"8","depth":"0"...
我想要的是:
{'data':[{"id":"1","parent_id":null,"lft":"1","rgt":"8","depth":"0"...
尝试使用:
Response::json(数组('data'=>array_值($yourDataArray))
尝试使用:
Response::json(数组('data'=>array_值($yourDataArray))
好的,在PHP中很容易,只需在初始数组上使用array_values(),这样它就“忘记”了数组索引(顺便说一下,在您的例子中,这就是“RootName_X”的名称:
$newvalue = array_values( (array)$value );
echo json_encode($newvalue);
好的,在PHP中很容易,只需在初始数组上使用array_values(),这样它就“忘记”了数组索引(顺便说一下,在您的例子中,这就是“RootName_X”的名称:
$newvalue = array_values( (array)$value );
echo json_encode($newvalue);
使用:
使用: