私はフォーマットのjsonファイルを持っています
{
"list" : {
"1" : {
"thing1" : "description",
"thing2" : "description",
"thing3" : "description"
},
"2" : {
"thing1" : "description",
"thing2" : "description",
"thing3" : "description"
},
etc.
}
事物2の説明に基づいてデータを検索して返す必要がありますが、リストの番号も返す必要があります。問題は、jsonファイルの番号がすべて順不同であるため、すべての番号を調べながら変数をインクリメントすることができないことです。
現在、コードは次のように設定されています。
$json = json_decode($response);
foreach($json->list as $item) {
$i++;
if($item->thing2 == "description") {
echo "<p>$item->thing1</p>";
echo "<p>$item->thing2</p>";
echo "<p>$item->thing3</p>";
echo "<p>position: $i</p><br /><br />";
}
}
残念ながら、$i変数が間違った位置を再調整するたびに位置が乱れているためです。適切なthing2の説明があるアイテムのタイトルを返すにはどうすればよいですか。