取消设置数组将键添加到 PHP 中的对象
Unsetting array adds key to objects in PHP
从 json 供稿中,我需要来自
$json['content']['locations']['location']['cams']['cam']['snow']['wi']
它包含 5 个对象。我需要对象 0、对象 1、对象 3 和对象 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 个对象,缺少键)
如何像第二个一样得到link?
解决方案
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;
改变
$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;
成功了。
从 json 供稿中,我需要来自
$json['content']['locations']['location']['cams']['cam']['snow']['wi']
它包含 5 个对象。我需要对象 0、对象 1、对象 3 和对象 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 个对象,缺少键)
如何像第二个一样得到link?
解决方案
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;
改变
$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;
成功了。