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?

Link to comment
Share on other sites

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'

      );

Link to comment
Share on other sites

<?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
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.