我需要一個數組,看起來像......壓縮PHP數組
array(11 => "fistVal", 19 => "secondVal", 120=> "thirdVal", 200 =>"fourthVal");
並將其轉換成...
array(0 => "fistVal", 1 => "secondVal", 2=> "thirdVal", 3 =>"fourthVal");
這是我想出了 -
function compressArray($array){
if(count($array){
$counter = 0;
$compressedArray = array();
foreach($array as $cur){
$compressedArray[$count] = $cur;
$count++;
}
return $compressedArray;
} else {
return false;
}
}
我只是好奇,如果有任何內置的功能在PHP或整潔的技巧來做到這一點。
重複:http://stackoverflow.com/questions/1111761/what-is-the-built-in-php-function-for-compressing-or-defragmenting-an-array – 2010-04-14 15:35:05