我不能使用array_values,因为我使用主键作为我的键数组 我使用123,124,125等..像这样
Array ( [123] => Array ( [123] => 100 [124] => 0.71428571428571 [125] => 0.46428571428571 [126] => 0.35714285714286 ) [124] => Array ( [123] => 0.71428571428571 [124] => 100 [125] => 0.53571428571429 [126] => 0.35714285714286 ) [125] => Array ( [123] => 0.46428571428571 [124] => 0.53571428571429 [125] => 100 [126] => 0.17857142857143 )
我使用unset来删除[127]并像这样成功
[123] = Array
[124] = Array
[125] = Array
[126] = Array
[128] = Array
[129] = Array
[130] = Array
但我不能用array_values安排数组键..
我想这样显示..你知道吗?
[123] = Array
[124] = Array
[125] = Array
[126] = Array
[127] = Array
[128] = Array
[129] = Array
答案 0 :(得分:0)
试试这个:
$array = array(/* your data here */);
// Remove the value(s) you don't need
unset($array[127]);
// Re-index the keys, starting with the first key from $array
// Get the first key of $array
$keys = array_keys($array);
$start = $keys[0];
// Compute the last key after re-index
$end = $start + count($array) - 1;
// Generate the new keys, combine them with the values
$fixed = array_combine(
range($start, $end), // generates array($start, $start+1, ... $end);
array_values($array)
);