3v4l.org

run code in 500+ PHP versions simultaneously
<?php $users = [ [ "id" => 1, "name" => "rahul", "premium" => true, "purchases" => ["apple", "banana", "carrot"], "price" => 22, ], [ "id" => 2, "name" => "abhi", "premium" => false, "purchases" => ["apple", "banana", "carrot"], "price" => 22, ], [ "id" => 3, "name" => "kavita", "premium" => true, "purchases" => ["apple", "banana", "carrot", "orange"], "price" => 30, ], ]; $premiumUsers = array_reduce( $users, function ($carry, $user) { if ($user['premium']) { $carry[] = [ "name" => $user["name"], "purchases" => $user["purchases"], "price" => $user["price"] - 2 ]; } return $carry; }, [] ); print_r($premiumUsers); /** * Array ( [0] => Array ( [name] => rahul [purchases] => Array ( [0] => apple [1] => banana [2] => carrot ) [price] => 20 ) [1] => Array ( [name] => kavita [purchases] => Array ( [0] => apple [1] => banana [2] => carrot [3] => orange ) [price] => 28 ) ) */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZViTK
function name:  (null)
number of ops:  12
compiled vars:  !0 = $users, !1 = $premiumUsers
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   26     1        INIT_FCALL                                                   'array_reduce'
   27     2        SEND_VAR                                                     !0
   28     3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
   37     4        SEND_VAL                                                     ~3
   38     5        SEND_VAL                                                     <array>
   26     6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !1, $4
   41     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
   74    11      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/ZViTK
function name:  {closure:/in/ZViTK:28}
number of ops:  15
compiled vars:  !0 = $carry, !1 = $user
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   29     2        FETCH_DIM_R                                          ~2      !1, 'premium'
          3      > JMPZ                                                         ~2, ->13
   31     4    >   FETCH_DIM_R                                          ~4      !1, 'name'
          5        INIT_ARRAY                                           ~5      ~4, 'name'
   32     6        FETCH_DIM_R                                          ~6      !1, 'purchases'
          7        ADD_ARRAY_ELEMENT                                    ~5      ~6, 'purchases'
   33     8        FETCH_DIM_R                                          ~7      !1, 'price'
          9        SUB                                                  ~8      ~7, 2
         10        ADD_ARRAY_ELEMENT                                    ~5      ~8, 'price'
   30    11        ASSIGN_DIM                                                   !0
   33    12        OP_DATA                                                      ~5
   36    13    > > RETURN                                                       !0
   37    14*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
146.65 ms | 3596 KiB | 15 Q