0

below is my array

$myarray = Array(
[1] => Array (['mytime']=>1),
[7] => Array(['mytime']=>2),
[2] => Array(['mytime']=>3),
[3] => Array(['mytime']=>4)
);

I want to sort output of this array based on keys...

$myarray = Array(
[1] => Array (['mytime']=>1),
[2] => Array(['mytime']=>3),
[3] => Array(['mytime']=>4),
[7] => Array(['mytime']=>2)
);

I have already tried ksort($myarray) it displays 1 anyways to fix this??

Your Friend
  • 1,119
  • 3
  • 12
  • 27

1 Answers1

0

ksort() does this:

ksort($myarray);

Note: sorting functions do not return a new sorted array; they simply sort the array passed, and return true or false. Thus, ksort($myarray) will return 1 when successful, and $myarray will be sorted.

It's very clear if you read the docs: http://php.net/manual/en/function.ksort.php

Mark Miller
  • 7,442
  • 2
  • 16
  • 22