...

View Full Version : Pulling back unique values from XML



steviecee
01-06-2007, 11:22 AM
hi, I'm populating a drop down select box with values from an XML file. I would like it to only populate with unique values, but with the code I have at the moment it only displays the first value, can anyone spot the problem?



$i = 0;
foreach ($entries as $entry) {
$arr[$i++] = $entry->nodeValue;
}
sort($arr);
$last_value = -1;
for ($j = 0; $j < $i; $j++) {
if ($arr[j] != $last_value) {
echo "<option value = '{$arr[$j]}'>{$arr[$j]}</option>";
$last_value = $arr[j];
}
}

cheers
Steve

GJay
01-06-2007, 12:10 PM
Take a look at array_unique() (http://php.net/array-unique), for example:


$array = array('one','two','three','two','one');
$unique_array = array_unique($array);
//$unique_array == array('one','two','three');

steviecee
01-06-2007, 12:37 PM
I've been playing around with this but I can't seem to get it to work in this context. how Icould I incorporate it into the drop down box?
cheers
Steve



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum