如何将键值从字符串更改为多维数组的数字? (codeigniter)

时间:2018-10-07 06:04:58

标签: arrays multidimensional-array codeigniter-3 array-key

我有一个多维数组。有细节

Array ( [0] => Array ( [score] => 2 [idks] => 3 [pasm] => 2 [qty] => 2 [qility] => 3 [point] => 2 [cls] => 5 [org] => 5 [outd] => 5 ) [1] => Array ( [score] => 5 [idks] => 4 [pasm] => 3 [qty] => 3 [qility] => 5 [point] => 3 [cls] => 5 [org] => 5 [outd] => 5 ) [2] => Array ( [score] => 3 [idks] => 2 [pasm] => 3 [qty] => 1 [qility] => 3 [point] => 1 [cls] => 4 [org] => 1 [outd] => 5 ) )

我需要像这样将键值更改为int

Array ( [0] => Array ( [0] => 2 [1] => 3 [2] => 2 [3] => 2 [4] => 3 [5] => 2 [6] => 5 [7] => 5 [8] => 5 ) [1] => Array ( [0] => 5 [1] => 4 [2] => 3 [3] => 3 [4] => 5 [5] => 3 [6] => 5 [7] => 5 [8] => 5 ) [2] => Array ( [0] => 3 [1] => 2 [2] => 3 [3] => 1 [4] => 3 [5] => 1 [6] => 4 [7] => 1 [8] => 5 ) )

我已经尝试过,但仍然失败。

1 个答案:

答案 0 :(得分:0)

通过使用array_value可以重置所有键

$arr = Array ( '0' => 
    Array ( 'score' => 2, 'idks' => 3, 'pasm' => 2, 'qty' => 2, 'qility' => 3, 'point' => 2, 'cls' => 5, 'org' => 5, 'outd' => 5),
     '1' => Array ( 'score' => 5, 'idks' => 4, 'pasm' => 3, 'qty' => 3, 'qility' => 5, 'point' => 3, 'cls' => 5, 'org' => 5, 'outd' => 5 ), 
     '2' => Array ( 'score' => 3, 'idks' => 2, 'pasm' => 3, 'qty' => 1, 'qility' => 3, 'point' => 1, 'cls' => 4, 'org' => 1, 'outd' => 5 ) );

$arr = array_map('array_values', $arr);
echo "<pre>";
print_r($arr);
echo "</pre>";
exit;