Hi how do I remove the duplicate desiredjobposition from this array below? <?PHP $array = json_decode($json_string); //exclude duplicates, only unique categories should come back //start of our select menu echo "<select>"; //Our Categories Menu foreach($array->results as $key => $object){ ?> <option value="<?PHP echo $object->meta_data-> desiredjobposition[0];?>"><?PHP echo $object->meta_data-> desiredjobposition[0];?></option> <?PHP } echo "</select>"; ?> PHP:
As mentioned that function will do what you ask, but it also might help if you weren't opening and closing PHP willy-nilly and using the most inefficient method of echo possible. Also if the value is the same as the HTML content of an OPTION tag, you don't need to say value="". You only say value="" when the value is DIFFERENT from the content text. (or in some strange javascript-tard corner cases involving IE8/earlier) <?php $array = json_decode($json_string); $results = array_unique($array->results); echo ' <select>'; foreach ($results as $object) echo ' <option>', $object->meta_data->desiredjobposition[0], '</option>'; echo ' </select>'; Code (markup): functionally identical, with the array_unique reduction implemented. Single quotes and comma delimits FTMFW. Oh, I also killed off $key since you weren't using it.