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.
配列があります:
$arr = array( 'AA' => 90, 'AB' => 150, 'BC' => 100, 'CD' => 60 );
と文字列:
$val = 'CD'
に対応する数値を定義するための(FORループなしの)簡単な方法はあります$valか?この例では、結果は60でなければなりません。
$val
あなたは文字通りただ必要$arr[$val]です。
$arr[$val]
echo $arr[$val];60を出力します。
echo $arr[$val];
$value = @$arr[$val];
必要なのはそれだけです