retoto Posted November 6, 2007 Share Posted November 6, 2007 <?php $array = array(0 => "bleu", 1 => "bleu", 2 => "ghgf", 3 => "gfhfgh"); $key = array_search('bleu', $array); echo #key; ?> you can see that i search "bleu" and i have two from that in array and this print on page only one... how can i print two thing ? (0,1) thanks Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 6, 2007 Share Posted November 6, 2007 <?php $array = array(0 => "bleu", 1 => "bleu", 2 => "ghgf", 3 => "gfhfgh"); $keys = array_keys($array, 'bleu'); print_r($keys); ?> Quote Link to comment Share on other sites More sharing options...
retoto Posted November 6, 2007 Author Share Posted November 6, 2007 <?php $array = array(0 => "bleu", 1 => "bleu", 2 => "ghgf", 3 => "gfhfgh"); $keys = array_keys($array, 'bleu'); print_r($keys); ?> thanks man but out pot " Array ( [0] => 0 [1] => 1 ) " how can i print only 0 and 1 without all this :\? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 6, 2007 Share Posted November 6, 2007 well you now have an array of the indexs of $array that match your search criteria... you can either loop through the array and echo each one out or implode the array into a string or what ever you want to do with it. Quote Link to comment Share on other sites More sharing options...
retoto Posted November 6, 2007 Author Share Posted November 6, 2007 you mean like that :S? <?php $array = array(0 => "bleu", 1 => "bleu", 2 => "ghgf", 3 => "gfhfgh"); for ($i=0;$i<=4;$i++) { $keys = array_keys($array[$i], 'bleu'); echo $keys; } ?> Warning: array_keys() [function.array-search]: Wrong datatype for second argument in *********** on line 4 Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 7, 2007 Share Posted November 7, 2007 you can't echo an array... print_r($array) yes but echo no.. try $strkeys = implode(' ', $keys); echo $strkeys; Quote Link to comment 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.