-2

There is an array:

$arr = array(
        'AA' => 90,
        'AB' => 150,
        'BC' => 100,
        'CD' => 60
);

and a string:

$val = 'CD'

Is there any quick way (without FOR loop) to define the numeric value corresponding to $val? In this example the result must be 60.

Excellll
  • 5,609
  • 4
  • 38
  • 55
You Kuper
  • 1,113
  • 7
  • 18
  • 38

2 Answers2

4

You literally just need $arr[$val].

echo $arr[$val]; will output 60.

SpaceBeers
  • 13,617
  • 6
  • 47
  • 61
2
$value = @$arr[$val];

it's all you need

Davuz
  • 5,040
  • 13
  • 41
  • 61