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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.