开发者

php array asort problem

this is my array:

$myarr = array(
               4 => 3,
               2 => 9,
               7 => 8,
               1 => 1
              );

when i do :

asort($myarr);

$myarr becomes:

array( 
      1 => 1,
      2 => 9,
      4 => 3,
      7 => 8
     );

This is not how it is supposed to work,right? the 开发者_运维知识库values should be sorted and keys maintained, while the reverse is happening - just like ksort. What can the problem be?

Please help me out.

Thanks


Works fine to me : http://codepad.org/o6pZ8ess

result :

array(4) {
  [1]=>
  int(1)
  [4]=>
  int(3)
  [7]=>
  int(8)
  [2]=>
  int(9)
}


Works fine for me, did you try:

asort($myarr, SORT_NUMERIC);


I believe this is not possible and the accepted answer is incorrect. I dont believe you can have integer keys in non numeric order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜