Jump to content


Photo

Problem with arsort and asort


  • Please log in to reply
2 replies to this topic

#1 atitthaker

atitthaker
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationBanglore, India

Posted 17 August 2006 - 12:16 PM

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

Beginner with PHP and need help

#2 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 17 August 2006 - 12:27 PM

Try without the SORT_STRING
I'm just a guy who likes to code for fun...

#3 atitthaker

atitthaker
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationBanglore, India

Posted 17 August 2006 - 12:31 PM

I don't know but it started working fine suddenly... I can't believe this thing.

Thanks anyway
Beginner with PHP and need help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users