Hello

Quick question about in_array and how to echo the results if it exists.

What I am wanting to do is check the below array for the variable $countryCode if it exists echo the $countryCode and the proceeding symbol in the array. But it doesnt seem to be working.

Here is the code and array



$symbol = array('USD' => '&#36', 'CAD' => '&#36', 'GBP' => '£', 'EUR' => '€', 'AUD' => '&#36');


$countryCode='EUR';


if (in_array($countryCode, $symbol)) {
    echo "";     //Wanting to echo the results of what was in the array Meaning CAD and the symbol associated with it  CAD €
}



Any Help would be appericated

Thanks

    in_array() is useful if you want to know if a particular value is in the array. If you want the associated key as well, then you should use [man]array_search/man instead.

      or you can try...

      $symbol = array('USD' => '&#36', 'CAD' => '&#36', 'GBP' => '£', 'EUR' => '€', 'AUD' => '&#36');
      
      
      $countryCode='EUR';
      
      if(isset($symbol[$countryCode])){
          echo "";     //Wanting to echo the results of what was in the array Meaning CAD and the symbol associated with it  CAD €
      }
      

        Oh, right. I misread and assumed that alganar was using in_array() correctly to begin with.

          Write a Reply...