I have a dropdown menu that need to be sorted alphabeticaly by name.
Here’s the code
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php
echo $option_value['name'];
if ($option_value['price']) {
?>(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)<?php
}
?>
</option>
<?php
}
?>
I want the $option_value to be sorted by the $option_value[‘name’]. How can I achieve this ?
Update
Using sort() or asort() before don’t fix the problem, the order I get is
<option value="14598">Medium - red (0588390) [0] </option>
<option value="14599">large - WHITE (0592167) [1] </option>
<option value="14600">Medium - WHITE (0592168) [3] </option>
<option value="14601">large - THE ROYALS (0592169) [0] </option>
<option value="14602">Medium - THE ROYALS (0592170) [2] </option>
It sort by the value ID but I need to be sorted by it’s name
Try this before your foreach: