Jump to content

Problem with arsort and asort


atitthaker

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....
Link to comment
https://forums.phpfreaks.com/topic/17832-problem-with-arsort-and-asort/
Share on other sites

Archived

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

×
×
  • Create New...

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.