3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateProductArray($database) { return array_reduce($database, function ($result, $entry) { [$model, $storage, $color] = array_values($entry); $result[$model][$storage][$color] = ($result[$model][$storage][$color] ?? 0) + 1; return $result; }, []); } // Example data from the database $database = array( array('model' => 'iPhone 14 Pro', 'storage' => '128gb', 'color' => 'Black'), array('model' => 'iPhone 14 Pro', 'storage' => '256gb', 'color' => 'Blue'), array('model' => 'iPhone 14 Pro', 'storage' => '128gb', 'color' => 'Black'), array('model' => 'iPhone 14 Pro', 'storage' => '256gb', 'color' => 'Red'), array('model' => 'iPhone 14 Pro', 'storage' => '256gb', 'color' => 'Red'), ); $resultArray = generateProductArray($database); print_r($resultArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tZaNW
function name:  (null)
number of ops:  9
compiled vars:  !0 = $database, !1 = $resultArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'generateproductarray'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   23     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function generateproductarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tZaNW
function name:  generateProductArray
number of ops:  9
compiled vars:  !0 = $database
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FtZaNW%3A4%240'
   10     4        SEND_VAL                                                 ~1
          5        SEND_VAL                                                 <array>
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   11     8*     > RETURN                                                   null

End of function generateproductarray

Function %00%7Bclosure%7D%2Fin%2FtZaNW%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tZaNW
function name:  {closure}
number of ops:  24
compiled vars:  !0 = $result, !1 = $entry, !2 = $model, !3 = $storage, !4 = $color
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'array_values'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $5      
          5        FETCH_LIST_R                                     $6      $5, 0
          6        ASSIGN                                                   !2, $6
          7        FETCH_LIST_R                                     $8      $5, 1
          8        ASSIGN                                                   !3, $8
          9        FETCH_LIST_R                                     $10     $5, 2
         10        ASSIGN                                                   !4, $10
         11        FREE                                                     $5
    7    12        FETCH_DIM_IS                                     ~15     !0, !2
         13        FETCH_DIM_IS                                     ~16     ~15, !3
         14        FETCH_DIM_IS                                     ~17     ~16, !4
         15        COALESCE                                         ~18     ~17
         16        QM_ASSIGN                                        ~18     0
         17        ADD                                              ~19     ~18, 1
         18        FETCH_DIM_W                                      $12     !0, !2
         19        FETCH_DIM_W                                      $13     $12, !3
         20        ASSIGN_DIM                                               $13, !4
         21        OP_DATA                                                  ~19
    9    22      > RETURN                                                   !0
   10    23*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FtZaNW%3A4%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.83 ms | 1407 KiB | 20 Q