3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cart_array = Session::get('products-cart'); $newProduct = ['id' => $request->product_id, 'qty' => $request->product_qty]; foreach($cart_array as &$item) { if ($item['id'] == $newProduct['id']) { $item = $newProduct; } } dd($cart_array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 126) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/WtCjI
function name:  (null)
number of ops:  22
compiled vars:  !0 = $cart_array, !1 = $newProduct, !2 = $request, !3 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_STATIC_METHOD_CALL                                  'Session', 'get'
          1        SEND_VAL_EX                                              'products-cart'
          2        DO_FCALL                                      0  $4      
          3        ASSIGN                                                   !0, $4
    4     4        FETCH_OBJ_R                                      ~6      !2, 'product_id'
          5        INIT_ARRAY                                       ~7      ~6, 'id'
          6        FETCH_OBJ_R                                      ~8      !2, 'product_qty'
          7        ADD_ARRAY_ELEMENT                                ~7      ~8, 'qty'
          8        ASSIGN                                                   !1, ~7
    6     9      > FE_RESET_RW                                      $10     !0, ->17
         10    > > FE_FETCH_RW                                              $10, !3, ->17
    7    11    >   FETCH_DIM_R                                      ~11     !3, 'id'
         12        FETCH_DIM_R                                      ~12     !1, 'id'
         13        IS_EQUAL                                                 ~11, ~12
         14      > JMPZ                                                     ~13, ->16
    8    15    >   ASSIGN                                                   !3, !1
    6    16    > > JMP                                                      ->10
         17    >   FE_FREE                                                  $10
   12    18        INIT_FCALL_BY_NAME                                       'dd'
         19        SEND_VAR_EX                                              !0
         20        DO_FCALL                                      0          
         21      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
276.07 ms | 1007 KiB | 13 Q