取消设置数组为PHP中的对象添加键

时间:2015-12-18 19:15:07

标签: php arrays json object unset

从json feed中,我需要四个对象 $json['content']['locations']['location']['cams']['cam']['snow']['wi']

它包含5个对象。我需要Object 0,Object 1,Object 3和Object 4.这就是我所做的: unset($json['content']['locations']['location']['cams']['cam']['snow']['wi'][2]);

在执行此操作之后,每个对象出现一个键(索引)之前。我不需要也不想要这些钥匙。 Array_values()无法解决问题。

$reindex = array_values($json); $json = $reindex;

直播:

http://www.api.bart-ros.nl/raurisertal/info2test(4个对象,密钥存在)

http://www.api.bart-ros.nl/raurisertal/info2(5个对象,没有密钥)

如何像第二个链接那样得到它?

unset($json['content']['locations']['location']['cams']['cam']['snow']['wi'][2]); $reindex = array_values($json['content']['locations']['location']['cams']['cam']['snow']['wi']); $json['content']['locations']['location']['cams']['cam']['snow']['wi'] = $reindex;

1 个答案:

答案 0 :(得分:0)

更改

$reindex = array_values($json); $json = $reindex;

$reindex = array_values($json['content']['locations']['location']['cams']['cam']['snow']['wi']); $json['content']['locations']['location']['cams']['cam']['snow']['wi'] = $reindex;

做了这个伎俩。