このセクションのPHPコードは、APIからの応答を受け取り、応答の特定の部分が変数と一致するかどうかを確認します。変数が配列の一部である場合の戻り値
以下のように...配列attribution
には、$this_id
に一致するsource_id
がありますか?
$this_id = 15;
$array = json_decode($response, true);
if (in_array($this_id, array_column($array['data']['attribution'], 'source_id'))) {
// then do this
}
else {
// then do this instead
}
これは完全に機能します。私がやろうとしているのは、APIをもう一度呼び出す必要なく、この配列から追加データを得ることです。ロジックは上記と同じですが、true
の場合は['data']['attribution']['item_number']
の値が返されます。 attribution
にはたくさんのオブジェクトが存在する可能性があることに注意してください。
この値を返すにはどうすればよいですか?
あなたはAPIへの呼び出しで '' [ 'ITEM_NUMBER']を渡すつもりですか? – Rahi