CodeIgniter Forums
Binary option for array_sort_by_multiple_keys? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Binary option for array_sort_by_multiple_keys? (/showthread.php?tid=84950)



Binary option for array_sort_by_multiple_keys? - bassmandc - 11-27-2022

I'm using the array_sort_by_multiple_keys function and finding that capital letters take order precedence over lowercase letters.  For example, "AZ Systems" comes before "Abracadabra," despite "Z" being after "b" alphabetically.  In an SQL query, this can be addressed with "ORDER BY column, binary(column) ASC".  Is there a way to address it using the array_sort_by_multiple_keys function?

NOTE:  I'm accomplishing this for the time being by running a foreach loop where I convert the text being alphabetized to lowercase, add it to the array with a different key, and then sort by that key.  I'd just love to skip the extra processing and extra array data if possible.

EDIT:  Accidentally left "_keys" off the end in the OP.


RE: Binary option for array_sort_by_multiple? - kenjis - 11-27-2022

Do you mean array_sort_by_multiple_keys()?
https://codeigniter4.github.io/CodeIgniter4/helpers/array_helper.html#array_sort_by_multiple_keys

Try
PHP Code:
'name' => SORT_STRING SORT_FLAG_CASE 



RE: Binary option for array_sort_by_multiple_keys? - bassmandc - 11-27-2022

Yes Kenjis - I meant array_sort_by_multiple_keys - bad copy and paste on my part.  I've corrected it.  Thanks for the reply - I'll try it out!