alvin567 Posted June 5, 2012 Share Posted June 5, 2012 $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? Quote Link to comment https://forums.phpfreaks.com/topic/263675-search-for-values-within-an-associative-array/ Share on other sites More sharing options...
phpSensei Posted June 5, 2012 Share Posted June 5, 2012 use the in_array function I dont know what you mean push 1 column to the right. Quote Link to comment https://forums.phpfreaks.com/topic/263675-search-for-values-within-an-associative-array/#findComment-1351261 Share on other sites More sharing options...
alvin567 Posted June 5, 2012 Author Share Posted June 5, 2012 Actually I saw a way to do it $data1 += array(1); isn't this pushing one array to the right? Quote Link to comment https://forums.phpfreaks.com/topic/263675-search-for-values-within-an-associative-array/#findComment-1351303 Share on other sites More sharing options...
alvin567 Posted June 5, 2012 Author Share Posted June 5, 2012 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' ); Quote Link to comment https://forums.phpfreaks.com/topic/263675-search-for-values-within-an-associative-array/#findComment-1351331 Share on other sites More sharing options...
Barand Posted June 5, 2012 Share Posted June 5, 2012 <?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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/263675-search-for-values-within-an-associative-array/#findComment-1351342 Share on other sites More sharing options...
alvin567 Posted June 5, 2012 Author Share Posted June 5, 2012 php array,say in a associative array, foreach($sales as $sale){ $sale['Sales']['Year'] $sale['Sales']['volume'] } I want to sum up all the volume together how can I do so? Quote Link to comment https://forums.phpfreaks.com/topic/263675-search-for-values-within-an-associative-array/#findComment-1351439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.