phparraysmultidimensional-arraycodeigniter-3array-key

how to change keys value from string to numeric of a multidimentional array? (codeigniter)


i have a multidimentional array. there is the details

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 ) )

i need to change the key value to int, like this

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 ) )

i've already tried but still failed.


Solution

  • By using array_value you can reset all keys

    $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;