3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_origin = [ [ "id" => 1, "category"=>1 ], [ "id" => 2, "category"=>2 ], ]; $array_origin = array_reduce($array_origin, static function($carry, $item) { $carry[] = $item; if ($item['category'] === 1) { $item['category'] = 2; $carry[] = $item; } return $carry; }, []); var_dump($array_origin);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJItn
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array_origin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
   24     4        SEND_VAL                                                 ~2
          5        SEND_VAL                                                 <array>
   15     6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !0, $3
   26     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
         11      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/aJItn
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        ASSIGN_DIM                                               !0
          3        OP_DATA                                                  !1
   18     4        FETCH_DIM_R                                      ~3      !1, 'category'
          5        IS_IDENTICAL                                             ~3, 1
          6      > JMPZ                                                     ~4, ->11
   19     7    >   ASSIGN_DIM                                               !1, 'category'
          8        OP_DATA                                                  2
   20     9        ASSIGN_DIM                                               !0
         10        OP_DATA                                                  !1
   23    11    > > RETURN                                                   !0
   24    12*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.56 ms | 1001 KiB | 15 Q