2014-05-06 345 views
0

我有以下數組結構。與變量$出擊給數組賦值

Array 
    (
     [0] => 480 
     [1] => 483 
     [2] => 497 
     [3] => 481 
     [4] => 478 
     [5] => 475 
     [6] => 476 
     [7] => 477 
     [8] => 498 
     [9] => 496 
     [10] => 502 
     [11] => 499 
     [12] => 494 
     [13] => 503 
     [14] => 493 
     [15] => 500 
     [16] => 484 
     [17] => 501 
     [18] => 495 
     [19] => 485 
     [20] => 489 
     [21] => 490 
     [22] => 488 
     [23] => 487 
     [24] => 486 
    ) 

我試圖通過使用下面的代碼的新陣列上賦予它們實現的東西。

 $release = array(); 
     foreach ($sortie as $key_true => $value_true) { 
      $release[$key_true] = $value_true; 
      echo $key_true.'---'.$value_true.'<br>'; 
     } 

到目前爲止,回聲結果會與正確的順序預期基於$架次

但是$釋放陣列沒有遵守不分配$ key_true相同的排序到$發佈數組。將不勝感激任何幫助爲什麼它這樣做。

編輯 對不起差點忘了,的結果$釋放值是原始密鑰和原始值

 Array 
    (
     [0] => 0---480 
     [1] => 1---483 
     [2] => 10---502 
     [3] => 11---499 
     [4] => 12---494 
     [5] => 13---503 
     [6] => 14---493 
     [7] => 15---500 
     [8] => 16---484 
     [9] => 17---501 
     [10] => 18---495 
     [11] => 19---485 
     [12] => 2---497 
     [13] => 20---489 
     [14] => 21---490 
     [15] => 22---488 
     [16] => 23---487 
     [17] => 24---486 
     [18] => 3---481 
     [19] => 4---478 
     [20] => 5---475 
     [21] => 6---476 
     [22] => 7---477 
     [23] => 8---498 
     [24] => 9---496 
    ) 
+2

你可以發佈你的'$ release'數組嗎? – Rikesh

+0

這只是一個巧合,$發佈值與您輸出的屏幕相同嗎? – khany

+0

'$ release = $ sortie;'? – sebasgo

回答

0

最好的做法是改變陣列這樣的結構:

$sortie = [480, 483, ...]; 
$release = []; 
foreach($sortie as $val) { 
    $release[$val] = true; 
} 

然後你可以使用php陣列sorting functions

0

嘗試把$ release == array();它可能會爲你工作,只要分配有關