I would like to merge duplicate values that i have in my drop down list, i dont want to use array_unique
because it deletes my second duplicate value. The way my program works is if you select a location it will populate my second drop down accordingly.
If you look at the picture provided you can see two duplicate entries Rosebank
when i click the first rosebank it will only show me on provider in my second drop down but when i click on the second rosebank it shows me all the providers with the location rosebank
. I would like to know if there is a way i can merge the two duplicates so that it will show me all the providers when i click rosebank
and it should only show one rosebank
.
Here is my code without array_unique
:
<label for="select-service">
<strong>Enter a Location:</strong>
</label>
<select class="form-control" id="select-location" class="col-xs-12 col-sm-4 form-control" required>
<option value="">Select Location</option>
<?php
foreach($appointment_locations as $location) {
$LocationsArray = explode(",", $location->notes);
foreach($LocationsArray as $singleLocation):
?>
<option value="<?=$singleLocation ?>"><?=$singleLocation ?></option>
<? endforeach;
};?>
</select>
and here is what i have tried with array_unique
, it successfully deletes the duplicates but as i said earlier, it will only show me one value in my next drop down and not all
<label for="select-service">
<strong>Enter a Location:</strong>
</label>
<select class="form-control" id="select-location" class="col-xs-12 col-sm-4 form-control" required>
<option value="">Select Location</option>
<?php
foreach(array_unique($appointment_locations) as $location) {
// foreach($appointment_locations as $location) {
$LocationsArray = explode(",", $location->notes);
foreach($LocationsArray as $singleLocation):
?>
<option value="<?=$singleLocation ?>"><?=$singleLocation ?></option>
<? endforeach;
};?>
</select>
here is my var_dump
array(2) {
[0]=>
object(stdClass)#28 (2) {
["id"]=>
string(1) "4"
["notes"]=>
string(29) "Randburg, Greenside, Rosebank"
}
[1]=>
object(stdClass)#29 (2) {
["id"]=>
string(1) "8"
["notes"]=>
string(8) "Rosebank"
}
}