JavaScriptを書いた後にPHPを書こうとするとUnderscore.jsやlodashのような簡潔な配列操作がしたいのにPHPだとよく知らないというケースが 個人的に よくあります。PHPの勉強不足ですね。 たとえばJavaScriptだと、こんな操作です。 const foundItem = _.find( items, (item) => { reuturn item.score === 2 }) 闇雲にforeachを使ってしまわないために、個人的な備忘録としてメモしておきたいと思います。 配列から要素を見つける(find) array_search という関数を利用します。返り値は要素ではなくキーです。 単純な値の配列の場合 $array = [1, 2, 3, 4]; $idx = array_search( 3, $array ); echo $idx; // 2 連想