3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [2, 3, 4, 6]; $array2 = [ ["id_sabor" => 1, "chocolate" => "N"], ["id_sabor" => 2, "chocolate" => "N"], ["id_sabor" => 3, "chocolate" => "S"], ["id_sabor" => 4, "chocolate" => "N"], ["id_sabor" => 5, "chocolate" => "S"], ["id_sabor" => 6, "chocolate" => "N"] ]; $array2 = array_reduce($array2, function($carry, $item) use ($array1){ if (in_array($item["id_sabor"], $array1)) { if ($item["chocolate"] === "S") { $item["costo_extra"] = 25; } $carry[] = $item; } return $carry; }); print_r($array2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/V5sFH
function name:  (null)
number of ops:  13
compiled vars:  !0 = $array1, !1 = $array2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
   13     2        INIT_FCALL                                               'array_reduce'
          3        SEND_VAR                                                 !1
          4        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          5        BIND_LEXICAL                                             ~4, !0
   21     6        SEND_VAL                                                 ~4
   13     7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !1, $5
   23     9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
         12      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 16
filename:       /in/V5sFH
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $carry, !1 = $item, !2 = $array1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   14     3        INIT_FCALL                                               'in_array'
          4        FETCH_DIM_R                                      ~3      !1, 'id_sabor'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8      > JMPZ                                                     $4, ->16
   15     9    >   FETCH_DIM_R                                      ~5      !1, 'chocolate'
         10        IS_IDENTICAL                                             ~5, 'S'
         11      > JMPZ                                                     ~6, ->14
   16    12    >   ASSIGN_DIM                                               !1, 'costo_extra'
         13        OP_DATA                                                  25
   18    14    >   ASSIGN_DIM                                               !0
         15        OP_DATA                                                  !1
   20    16    > > RETURN                                                   !0
   21    17*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.52 ms | 1003 KiB | 16 Q