从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;
答案 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;
做了这个伎俩。