Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
配列に値が1つしかないかどうか、その特定の値が「ホーム」であるかどうかを確認しようとしています。以下の方法はこれを達成するための最良の方法ですか、それとも 1 つのステップで実行できますか?
お気に入り:
$mymenu; // array if(count($mymenu) < 2 && in_array('Home', $mymenu)){ // Do something }
この三項演算子を試してみてください...
echo count($mymenu) === 1 && $mymenu[0] === 'Home' ? 'Do something' : null;