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 Link to comment https://forums.phpfreaks.com/topic/76231-stuck-in-function/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/76231-stuck-in-function/#findComment-385809 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 :\? Link to comment https://forums.phpfreaks.com/topic/76231-stuck-in-function/#findComment-385836 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. Link to comment https://forums.phpfreaks.com/topic/76231-stuck-in-function/#findComment-385857 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 Link to comment https://forums.phpfreaks.com/topic/76231-stuck-in-function/#findComment-385895 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; Link to comment https://forums.phpfreaks.com/topic/76231-stuck-in-function/#findComment-386227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.