开发者

php array asort problem

开发者 https://www.devze.com 2023-01-22 21:09 出处:网络
this is my array: $myarr = array( 4 => 3, 2 => 9, 7 => 8, 1 => 1 ); when i do : asort($myarr); $myarr becomes:

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

精彩评论

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