Archive for December, 2009
access associative array in_array
No Comments »
December 1st, 2009 Posted 9:09 am
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!
Posted in php
