Sorrting an array in PHP: Does this look sorted ?

AFB

Lifer
Jan 10, 2004
10,718
3
0
I want to sort like the link says but it doesn't work. Is their any way else to do this ?

Text
Does this look sorted :
bow.jpeg
pobchnga.jpeg
word.jpeg
war.jpeg
Rice.jpg
bookg.jpeg
Abstract 1.jpg
Aqua Blue (Original).jpg
AquaGrey.jpg
plane.jpeg
Panther.jpg
OSX-1024x768.jpg
shcool.jpeg
bunny.gif
athlonrapep4.jpeg
accident_missle.jpeg
pied.jpeg
beer.jpeg
between_lines.jpeg
booka.jpeg
christ_action.jpeg
changeme.jpeg
dad.jpeg
hitler.jpeg
jesuslovesyou.jpeg
jesusheat.jpeg
mafia.jpeg
parade.gif
noob.jpeg
pregnancy.jpeg
riaa.gif
amd.jpeg
beer.JPG
bush.jpeg
fag_bearings_corp.jpeg
Bliss_mod_By_Recall_scr.jpg
Longhorn_Aero_Grassy.jpg
Longhorn_System_Failure.jpg
red longhorn.bmp
m6.jpg
billgates.jpeg
newscast.jpeg
gramnazi.PNG
AquaBlue.jpg
chinese_bathroom_sign.jpeg
hornyremover.jpeg
urine_tshirt.jpeg
speling1.jpeg
toydanger.jpeg
girlsevil.jpeg
IntelEvilInside.jpeg
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
It works -- I've used it myself. If you read the comments on that page, you'd see that it works for others as well. Do you really think such a common function in the standard library of an immensely popular language such as PHP would just "not work"?
 

alexXx

Senior member
Jun 4, 2002
502
0
0
You could easily write your own sort algorithm, but the built in functions DO work and will be faster
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Text
Scroll down and click on index at the bottom. The links are not being sorted from the "$array" array.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Does this look sorted :
bow.jpeg
pobchnga.jpeg
word.jpeg
war.jpeg
Rice.jpg
bookg.jpeg
Abstract 1.jpg
Aqua Blue (Original).jpg
AquaGrey.jpg
plane.jpeg
Panther.jpg
OSX-1024x768.jpg
shcool.jpeg
bunny.gif
athlonrapep4.jpeg
accident_missle.jpeg
pied.jpeg
beer.jpeg
between_lines.jpeg
booka.jpeg
christ_action.jpeg
changeme.jpeg
dad.jpeg
hitler.jpeg
jesuslovesyou.jpeg
jesusheat.jpeg
mafia.jpeg
parade.gif
noob.jpeg
pregnancy.jpeg
riaa.gif
amd.jpeg
beer.JPG
bush.jpeg
fag_bearings_corp.jpeg
Bliss_mod_By_Recall_scr.jpg
Longhorn_Aero_Grassy.jpg
Longhorn_System_Failure.jpg
red longhorn.bmp
m6.jpg
billgates.jpeg
newscast.jpeg
gramnazi.PNG
AquaBlue.jpg
chinese_bathroom_sign.jpeg
hornyremover.jpeg
urine_tshirt.jpeg
speling1.jpeg
toydanger.jpeg
girlsevil.jpeg
IntelEvilInside.jpeg
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Doesn't it seem like a bad idea to give a variable the same name as a built in keyword? (array)

Not sure what else would be the problem.
 

Extrarius

Senior member
Jul 8, 2001
259
0
0
From the page you linked to in the OP (http://www.php.net/manual/en/function.natcasesort.php), as the third comment :
Originally posted by: dslicer at maine dot rr dot com
Something that should probably be documented is the fact that both natsort and natcasesort maintain the key-value associations of the array. If you natsort a numerically indexed array, a for loop will not produce the sorted order; a foreach loop, however, will produce the sorted order, but the indices won't be in numeric order. If you want natsort and natcasesort to break the key-value associations, just use array_values on the sorted array, like so:

natcasesort($arr);
$arr = array_values($arr);
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Extrarius
From the page you linked to in the OP (http://www.php.net/manual/en/function.natcasesort.php), as the third comment :
Originally posted by: dslicer at maine dot rr dot com
Something that should probably be documented is the fact that both natsort and natcasesort maintain the key-value associations of the array. If you natsort a numerically indexed array, a for loop will not produce the sorted order; a foreach loop, however, will produce the sorted order, but the indices won't be in numeric order. If you want natsort and natcasesort to break the key-value associations, just use array_values on the sorted array, like so:

natcasesort($arr);
$arr = array_values($arr);

<--Hugs you.


:beer: 4 U