Re: [PHP] sorting array by keys?
- Date: Wed, 21 Oct 2015 09:59:58 +0300
- From: Tolga <kacmaztolga@xxxxxxxxx>
- Subject: Re: [PHP] sorting array by keys?
21.10.2015 09:50 tarihinde Jeffry Killen yazdı:
its probably because of sorting algorithms checks char to char, first
orders 1st char, then second, then .... , not by their numeric values.
I have been consulting the manual and playing with a few different
approaches to this;
this comes the closest to what I want:
function sortAlg($_a, $_b)
return strcasecmp($_a, $_b);
$_result['dirs'] is itself an array where the associative string keys
are what I want to sort by.
Everything works fine, accept
I have a series of directories that follow the naming pattern 'lab_#'
so, what happens with the sort is that the labs come out
... etc... up to lab_13
... etc... up to lab_9
Am I going to have to code to find these cases and sort them as a
separate array by keys?
This is also coming out of Apache on a FreeBSD system. The sorting
order appears to be
creation date, as the last items created in this part of the file
system appear last without any
Without any sorting most of the lab_# names come out in the right
order, but that is, I believe,
because all of these directories and files were posted via ftp
transfer at the same time.
So, lab_0 through lab_8 come out in the right order, but lab_9 through
lab_13 seem to
appear according to subsequent creation date.
You first need to sort as you are doing now, then collect all the names
with same starting letters into new array,
(for your example, collect all names with starting 'lab_' into new array)
then compare/sort new arrays with using filter_var($str,
therefore, you can sort names with numeric values on last step of sorting.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php