Link to home
Start Free TrialLog in
Avatar of Mr_Splash
Mr_Splash

asked on

Sorting array returns 1

Hello,

I'm using the array in the snippet beow.

You'll see that the third item has a lower index than the second. When I try to apply sort() to the array it just returns 1.

How can I sort the array so that they display in numerical index order?

Thanks
Array (
  [1209575532] => Array (
    [id] => 1 [title] => News Headline! [date] => 02-05-2008 [text] => Pellentesque id orci.
  ) 
  [1217524332] => Array (
    [id] => 2 [title] => New News! [date] => 09-08-2008 [text] => Morbi commodo.
  )
  [1214845932] => Array (
    [id] => 3 [title] => Go News! [date] => 06-07-2008 [text] => Quisque condimentum.
  ) 
)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mr_Splash
Mr_Splash

ASKER

Hi Hernst,

using ksort also returns 1.

print_r($array); = returns the text in my snippet above.

print_r(ksort($array)); = returns 1

Any ideas?
Yes thats correct, if you had read the documentation of ksort/sort and it's return value
Read http://www.php.net/ksort
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial