3v4l.org

run code in 300+ PHP versions simultaneously
<?php $original = Array ( 'id' => Array ( 0 => 1, 1 => 3 ), 'reward' => Array ( 0 => 'Movie', 1 => 'Trip' ), 'cost' => Array ( 0 => 50, 1 => 200 ) ); $output = array(); // Iterate the original array's [id] sub-array foreach ($original['id'] as $idxkey => $newkey) { // Add a sub-array using $newkey to the output array $output[$newkey] = array( // Using the index (not value), retrieve the corresponding reward // value to use as the new array key // and corresponding cost to use as the new subarray value $original['reward'][$idxkey] => $original['cost'][$idxkey] ); } print_r($output);

preferences:
49.55 ms | 402 KiB | 5 Q