Jump to content

Archived

This topic is now archived and is closed to further replies.

atitthaker

Problem with arsort and asort

Recommended Posts

I am getting unexpected result while sorting with arsort() and asort()...
The code and given output are as given below...

----------------------------
print("</br>Revese sorting array by arsort </br>");
$myArray=array("apple","banana","grapes","lotus","red","green");
arsort($myArray,SORT_STRING);
print_r($myArray);


print("</br>Sorting array by asort </br>");
$myArray=array("apple","banana","grapes","lotus","red","green");
asort($myArray,SORT_STRING);
print_r($myArray);

------------------------------

The output I get is:
------------------------------

Revese sorting array by arsort Array
(
    [4] => red
    [5] => green
    [3] => lotus
    [2] => grapes
    [1] => banana
    [0] => apple
)
Sorting array by asort Array
(
    [1] => banana
    [0] => apple
    [2] => grapes
    [3] => lotus
    [5] => green
    [4] => red
)

What I mean is it is not changing the order of 'banana' and 'apple' why so?
Even the order it is generating is not understanable.

If someone can make it clear please help....

Share this post


Link to post
Share on other sites
Try without the SORT_STRING

Share this post


Link to post
Share on other sites
I don't know but it started working fine suddenly... I can't believe this thing.

Thanks anyway

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.