-2

I've searched but can't find a solution that works.

I have the following code - how can I ensure that the output is sorted alphabetically by $location["title"] ?

    <?php foreach($countries as $country): ?>
<option value="<?php $country["title"] ?>"><?php esc_html_e($country["title"]) ?>
    <?php endforeach; ?>

Many thanks

IMSoP
  • 89,526
  • 13
  • 117
  • 169
Keith Taylor
  • 13
  • 1
  • 5
  • 1
    I'm sorry, but there must be dozens of questions on here about this already, I find it hard to believe you searched the site and didn't find them. If your situation is somehow different from every single example you found, you need to explain how, but it looks like a pretty simple case to me. – IMSoP Apr 15 '15 at 15:30
  • Thanks - I obviously didn't search hard enough. – Keith Taylor Apr 15 '15 at 19:39

1 Answers1

0

you can use this:

function compareByName($a, $b) {
  return strcmp($a["name"], $b["name"]);
}
usort($countries, 'compareByName');
Aryeh Armon
  • 2,137
  • 2
  • 22
  • 37