3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cols = Array ( 0 => 'Name', 1 => 'MCR', 2 => 'MCD', 3 => 'COM', 4 => 'INV', 5 => 'IDM', 6 => 'PPO', 7 => 'HKD', 8 => 'ALL', 9 => 'POS', 10 => 'MCD-SP', 11 => 'MCD-BH', 12 => 'MCD-CL', 13 => 'MCD-CO', 14 => 'MCR-SP', 15 => 'MCR-PO' ); $rows = Array( 0 => Array( 0 => 'Primero', 1 => 19683.43, 2 => NULL, 3 => 3757.38, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => NULL, 11 => NULL, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ), 1 => Array ( 0 => 'Segundo', 1 => 15340.5767, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => NULL, 11 => NULL, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ), 2 => Array ( 0 => 'Tercero', 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => 4969.65, 11 => NULL, 12 => NULL, 13 => NULL, 14 => 23695.39, 15 => NULL ), 3 => Array ( 0 => 'Cuarto', 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => NULL, 11 => 45974.86, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ), 4 => Array ( 0 => 'Quinto', 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => 1405.8, 11 => 39244, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ) ); $qty_col = count($cols) - 1; $qty_rows = count($rows); //echo $qty_rows; $ifScript = ''; for ($a = 1; $a <= $qty_col; $a++) { $unsetScript = 'unset('; $ifScript .='if('; for ($b = 0; $b <= $qty_rows; $b++) { $ifScript .= 'empty($rows[' . $b . '][' . $a . '])'; $unsetScript .='$rows[' . $b . '][' . $a . ']'; if ($b == $qty_rows) { $ifScript .='){'; //$ifScript .='){<br>'; $unsetScript .=', $cols[' . $a . ']);'; } else { $ifScript .= ' && '; $unsetScript .=', '; } } $ifScript .= $unsetScript . '}'; //$ifScript .= $unsetScript . '<br>}<br>'; } //echo $ifScript; eval($ifScript); $cols = array_values($cols); $rows = array_map('array_values', $rows); foreach ($cols as $key => $value) { $cols[$key] = array( 'id' => NULL, 'label' => $value ); $type = ($key == 0) ? 'string' : 'number'; $cols[$key]['type'] = $type; } foreach ($rows as $key1 => $value1) { foreach ($value1 as $key2 => $value2) { $val = (empty($value2)) ? '0.00' : $value2; $format = ($key2 == 0) ? strtoupper(trim($value2)) : '$' . number_format($value2, '2', '.', ','); $value1[$key2] = array( 'v' => $val, 'f' => $format ); } $rows[$key1] = array( 'c' => $value1 ); } $newArray = array( 'cols' => $cols, 'rows' => $rows ); echo '<pre>'; print_r($newArray); echo '</pre>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 10
Branch analysis from position: 41
2 jumps found. (Code = 77) Position 1 = 52, Position 2 = 68
Branch analysis from position: 52
2 jumps found. (Code = 78) Position 1 = 53, Position 2 = 68
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 62
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 68
2 jumps found. (Code = 77) Position 1 = 70, Position 2 = 110
Branch analysis from position: 70
2 jumps found. (Code = 78) Position 1 = 71, Position 2 = 110
Branch analysis from position: 71
2 jumps found. (Code = 77) Position 1 = 73, Position 2 = 105
Branch analysis from position: 73
2 jumps found. (Code = 78) Position 1 = 74, Position 2 = 105
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 79
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 91
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 91
Branch analysis from position: 83
Branch analysis from position: 91
Branch analysis from position: 105
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 105
Branch analysis from position: 110
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 110
Branch analysis from position: 68
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 14
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 10
Branch analysis from position: 41
Branch analysis from position: 10
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 14
Branch analysis from position: 36
Branch analysis from position: 14
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 14
Branch analysis from position: 36
Branch analysis from position: 14
filename:       /in/IlDj2
function name:  (null)
number of ops:  120
compiled vars:  !0 = $cols, !1 = $rows, !2 = $qty_col, !3 = $qty_rows, !4 = $ifScript, !5 = $a, !6 = $unsetScript, !7 = $b, !8 = $value, !9 = $key, !10 = $type, !11 = $value1, !12 = $key1, !13 = $value2, !14 = $key2, !15 = $val, !16 = $format, !17 = $newArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN                                                   !1, <array>
  119     2        COUNT                                            ~20     !0
          3        SUB                                              ~21     ~20, 1
          4        ASSIGN                                                   !2, ~21
  120     5        COUNT                                            ~23     !1
          6        ASSIGN                                                   !3, ~23
  123     7        ASSIGN                                                   !4, ''
  124     8        ASSIGN                                                   !5, 1
          9      > JMP                                                      ->39
  125    10    >   ASSIGN                                                   !6, 'unset%28'
  126    11        ASSIGN_OP                                     8          !4, 'if%28'
  127    12        ASSIGN                                                   !7, 0
         13      > JMP                                                      ->34
  128    14    >   CONCAT                                           ~30     'empty%28%24rows%5B', !7
         15        CONCAT                                           ~31     ~30, '%5D%5B'
         16        CONCAT                                           ~32     ~31, !5
         17        CONCAT                                           ~33     ~32, '%5D%29'
         18        ASSIGN_OP                                     8          !4, ~33
  129    19        CONCAT                                           ~35     '%24rows%5B', !7
         20        CONCAT                                           ~36     ~35, '%5D%5B'
         21        CONCAT                                           ~37     ~36, !5
         22        CONCAT                                           ~38     ~37, '%5D'
         23        ASSIGN_OP                                     8          !6, ~38
  130    24        IS_EQUAL                                                 !7, !3
         25      > JMPZ                                                     ~40, ->31
  131    26    >   ASSIGN_OP                                     8          !4, '%29%7B'
  133    27        CONCAT                                           ~42     '%2C+%24cols%5B', !5
         28        CONCAT                                           ~43     ~42, '%5D%29%3B'
         29        ASSIGN_OP                                     8          !6, ~43
         30      > JMP                                                      ->33
  135    31    >   ASSIGN_OP                                     8          !4, '+%26%26+'
  136    32        ASSIGN_OP                                     8          !6, '%2C+'
  127    33    >   PRE_INC                                                  !7
         34    >   IS_SMALLER_OR_EQUAL                                      !7, !3
         35      > JMPNZ                                                    ~48, ->14
  139    36    >   CONCAT                                           ~49     !6, '%7D'
         37        ASSIGN_OP                                     8          !4, ~49
  124    38        PRE_INC                                                  !5
         39    >   IS_SMALLER_OR_EQUAL                                      !5, !2
         40      > JMPNZ                                                    ~52, ->10
  145    41    >   INCLUDE_OR_EVAL                                          !4, EVAL
  146    42        INIT_FCALL                                               'array_values'
         43        SEND_VAR                                                 !0
         44        DO_ICALL                                         $54     
         45        ASSIGN                                                   !0, $54
  147    46        INIT_FCALL                                               'array_map'
         47        SEND_VAL                                                 'array_values'
         48        SEND_VAR                                                 !1
         49        DO_ICALL                                         $56     
         50        ASSIGN                                                   !1, $56
  149    51      > FE_RESET_R                                       $58     !0, ->68
         52    > > FE_FETCH_R                                       ~59     $58, !8, ->68
         53    >   ASSIGN                                                   !9, ~59
  151    54        INIT_ARRAY                                       ~62     null, 'id'
  152    55        ADD_ARRAY_ELEMENT                                ~62     !8, 'label'
  150    56        ASSIGN_DIM                                               !0, !9
  152    57        OP_DATA                                                  ~62
  154    58        IS_EQUAL                                                 !9, 0
         59      > JMPZ                                                     ~63, ->62
         60    >   QM_ASSIGN                                        ~64     'string'
         61      > JMP                                                      ->63
         62    >   QM_ASSIGN                                        ~64     'number'
         63    >   ASSIGN                                                   !10, ~64
  155    64        FETCH_DIM_W                                      $66     !0, !9
         65        ASSIGN_DIM                                               $66, 'type'
         66        OP_DATA                                                  !10
  149    67      > JMP                                                      ->52
         68    >   FE_FREE                                                  $58
  158    69      > FE_RESET_R                                       $68     !1, ->110
         70    > > FE_FETCH_R                                       ~69     $68, !11, ->110
         71    >   ASSIGN                                                   !12, ~69
  159    72      > FE_RESET_R                                       $71     !11, ->105
         73    > > FE_FETCH_R                                       ~72     $71, !13, ->105
         74    >   ASSIGN                                                   !14, ~72
  160    75        ISSET_ISEMPTY_CV                                         !13
         76      > JMPZ                                                     ~74, ->79
         77    >   QM_ASSIGN                                        ~75     '0.00'
         78      > JMP                                                      ->80
         79    >   QM_ASSIGN                                        ~75     !13
         80    >   ASSIGN                                                   !15, ~75
  161    81        IS_EQUAL                                                 !14, 0
         82      > JMPZ                                                     ~77, ->91
         83    >   INIT_FCALL                                               'strtoupper'
         84        INIT_FCALL                                               'trim'
         85        SEND_VAR                                                 !13
         86        DO_ICALL                                         $78     
         87        SEND_VAR                                                 $78
         88        DO_ICALL                                         $79     
         89        QM_ASSIGN                                        ~80     $79
         90      > JMP                                                      ->99
         91    >   INIT_FCALL                                               'number_format'
         92        SEND_VAR                                                 !13
         93        SEND_VAL                                                 '2'
         94        SEND_VAL                                                 '.'
         95        SEND_VAL                                                 '%2C'
         96        DO_ICALL                                         $81     
         97        CONCAT                                           ~82     '%24', $81
         98        QM_ASSIGN                                        ~80     ~82
         99    >   ASSIGN                                                   !16, ~80
  163   100        INIT_ARRAY                                       ~85     !15, 'v'
  164   101        ADD_ARRAY_ELEMENT                                ~85     !16, 'f'
  162   102        ASSIGN_DIM                                               !11, !14
  164   103        OP_DATA                                                  ~85
  159   104      > JMP                                                      ->73
        105    >   FE_FREE                                                  $71
  168   106        INIT_ARRAY                                       ~87     !11, 'c'
  167   107        ASSIGN_DIM                                               !1, !12
  168   108        OP_DATA                                                  ~87
  158   109      > JMP                                                      ->70
        110    >   FE_FREE                                                  $68
  172   111        INIT_ARRAY                                       ~88     !0, 'cols'
  173   112        ADD_ARRAY_ELEMENT                                ~88     !1, 'rows'
  171   113        ASSIGN                                                   !17, ~88
  175   114        ECHO                                                     '%3Cpre%3E'
  176   115        INIT_FCALL                                               'print_r'
        116        SEND_VAR                                                 !17
        117        DO_ICALL                                                 
  177   118        ECHO                                                     '%3C%2Fpre%3E'
        119      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.69 ms | 1408 KiB | 25 Q