There is a multidimensional array:

Array ( [0] => Array ( [0] => msi [1] => im [2] => rec [3] => orig_tor ) [1] => Array ( [0] => 911 [1] => 2150 [2] => 10 [3] => 7 ) ) 

You need to change the array key (rename, in fact, swap) array[0][1] to array[0][2] and array[0][2] to array[0][1] and so on for each nested array for keys [1] and [2].

  • Change the values ​​of these keys in places. - Visman
  • How can I do that? - Dima Kuzmin
  • one
    You can use php.net/manual/ru/function.list.php list () to exchange values ​​without additional variables. - Visman

2 answers 2

 $array=[....]; foreach($array as &$inner){ $temp = $inner[2]; $inner[2] = $inner[1]; $inner[1] = $temp; } 

    Made according to the recommendation of @Visman

     $result=[....]; $keys = array_keys($result); for($i = 0; $i < count($result); $i++) { foreach($result[$keys[$i]] as $key => $value) { list($result[$keys[$i]][3], $result[$keys[$i]][2]) = array($result[$keys[$i]][2], $result[$keys[$i]][3]); } }