0

I have an array populated dynamically from customers data in a foreach loop. It looks like this : "Émilie Champagne" => "array",

$customers = get_customers_from_orders( $customers_orders ); // Get an array of customers data
if ( $customers !== 'empty' ) {
  
  $customers_items = array();
  foreach ( $customers as $customer ) {
    $html = '';
    // THE CUSTOM LIST ITEM
    $html .= '<li order_id="'.$customer['order_id'].'" email="'.$customer['email'].'">';
    $html .= $customer['name'];
    $html .= '</li>';
    $customers_items[$customer['name']] = $html;
  }
  ksort( $customers_items );
  foreach ( $customers_items as $customer_item ) {
    $customer_list .= $customer_item;
  }
}

When i use the ksort, its working but only one customer at the end is not sorted correctly.

Screenshot showing the result

You can see the last item is starting with letter "E".

The same thing happens on 3 others ksort function on the same page.

Any idea how i could fix this?

  • 1
    Salut Gabriel, note that `É` is not == to `E` for a computer. Check the flags for `ksort` (https://www.php.net/manual/en/function.ksort.php), maybe the locale could be useful. Check this too: https://stackoverflow.com/questions/120334/how-to-sort-an-array-of-utf-8-strings – Nic3500 Jul 14 '21 at 01:18
  • FYI, refrain from putting images in your question, especially since it is text. And to provide a good [mcve], you should add a complete example of your data array. We could then try your code. – Nic3500 Jul 14 '21 at 01:20

0 Answers0