Jump to content

Search for values within an associative array


alvin567

Recommended Posts

$practitioners = array('1' => 1, '2'=> 2,'3'=>3,'4'=>4,'5'=>5,'6'=>6

      ,'7'=>7,'8'=>8,'9'=>'9','10'=>10,'11-19'=>'11-19','20-40'=>'20-40','Over 40'=>'Over 40'

      );

 

How do I search for values in associative array,

search that when i find the value '1' and if it is founded I will push one column to the right?

Ok,for example if I search for 11-19 will I get the value can i adjust the values?

 

  $practitioners = array('1' => 1, '2'=> 2,'3'=>3,'4'=>4,'5'=>5,'6'=>6

      ,'7'=>7,'8'=>8,'9'=>'9','10'=>10,'11-19'=>'11-19','20-40'=>'20-40','Over 40'=>'Over 40'

      );

<?php
$practitioners = array('1' => 1, '2'=> 2,'3'=>3,'4'=>4,'5'=>5,'6'=>6
      ,'7'=>7,'8'=>8,'9'=>'9','10'=>10,'11-19'=>'11-19','20-40'=>'20-40','Over 40'=>'Over 40'
      );
      

// if "11-19" is the key you are searching 
// for and you want the value

echo $practitioners['11-19'];                             // --> 11-19

// if "11-19" is the value you are searching 
// for and you want the key

echo array_search('11-19' , $practitioners);              // --> 11-19

// but with an array like that you
// may as well just

echo '11-19';                                             // --> 11-19
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.