Breathing Spring

access associative array in_array

so let me explain this
usually we have arrays like this

$my_array= new Array ("US","UK", "FR")
and to search for a value we do
if( in_array("FR", $my_array) )

the problem is when we have an associative array that has several values something like this

$my_array= new Array ("US"=>array(40,50) ,"UK"=>array(46,60) , "FR"=>array(70,50) );

now searching for FR wont be possible with the previous way

so what we do is simple easy add!

if(in_array("FR" ,array_keys($my_array)))

enjoy!

This entry was posted on Tuesday, December 1st, 2009 at 9:09 am and is filed under php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.