php_novice2007 Posted May 7, 2007 Share Posted May 7, 2007 Hi, I'm trying to use the array_unique function and its not giving me some of my values... So for example, $input = array("4", "4", "3", "4", "3", "5","7","7"); $indiGroup = array_unique($input); for($j=0; $j < count($indiGroup); $j++) { print "<option value=$indiGroup[$j]>$indiGroup[$j]</option>"; } When I put this code in my page, my drop down lists has "4", and then a gap, and then "3", and then a gap.. It seems to be missing every second one. ??? Link to comment https://forums.phpfreaks.com/topic/50317-solved-array_unique/ Share on other sites More sharing options...
genericnumber1 Posted May 7, 2007 Share Posted May 7, 2007 print_r() the $indiGroup? Link to comment https://forums.phpfreaks.com/topic/50317-solved-array_unique/#findComment-247029 Share on other sites More sharing options...
warewolfe Posted May 7, 2007 Share Posted May 7, 2007 replace for($j=0; $j < count($indiGroup); $j++) { print "<option value=$indiGroup[$j]>$indiGroup[$j]</option>"; } with foreach($indiGroup as $val){ echo"<option = $val> $val </option>";} Link to comment https://forums.phpfreaks.com/topic/50317-solved-array_unique/#findComment-247049 Share on other sites More sharing options...
php_novice2007 Posted May 7, 2007 Author Share Posted May 7, 2007 Sweet, thanks~! I'm curious... How come the other way didn't work? Link to comment https://forums.phpfreaks.com/topic/50317-solved-array_unique/#findComment-247181 Share on other sites More sharing options...
genericnumber1 Posted May 7, 2007 Share Posted May 7, 2007 I don't believe you can use variables for array indexes inside of double quotes... you probably could have done... print "<option value=" . $indiGroup[$j] . ">" . $indiGroup[$j] . "</option>"; with no problems Link to comment https://forums.phpfreaks.com/topic/50317-solved-array_unique/#findComment-247436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.