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);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/2pac3
function name:  (null)
number of ops:  19
compiled vars:  !0 = $original, !1 = $output, !2 = $newkey, !3 = $idxkey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   18     1        ASSIGN                                                   !1, <array>
   21     2        FETCH_DIM_R                                      ~6      !0, 'id'
          3      > FE_RESET_R                                       $7      ~6, ->14
          4    > > FE_FETCH_R                                       ~8      $7, !2, ->14
          5    >   ASSIGN                                                   !3, ~8
   27     6        FETCH_DIM_R                                      ~11     !0, 'reward'
          7        FETCH_DIM_R                                      ~12     ~11, !3
          8        FETCH_DIM_R                                      ~13     !0, 'cost'
          9        FETCH_DIM_R                                      ~14     ~13, !3
         10        INIT_ARRAY                                       ~15     ~14, ~12
   23    11        ASSIGN_DIM                                               !1, !2
   27    12        OP_DATA                                                  ~15
   21    13      > JMP                                                      ->4
         14    >   FE_FREE                                                  $7
   31    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.36 ms | 1399 KiB | 15 Q