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]; if (!Session::has(['id' => $request->product_id])) { $cart_array->push(['id' => $request->product_id, 'count' => $request->product_qty]); } else{ foreach($cart_array as &$item) { if ($item['id'] == $newProduct['id']) { $item = $newProduct; } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 125) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
2 jumps found. (Code = 126) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/ZQEhQ
function name:  (null)
number of ops:  34
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        INIT_STATIC_METHOD_CALL                                  'Session', 'has'
         10        FETCH_OBJ_R                                      ~10     !2, 'product_id'
         11        INIT_ARRAY                                       ~11     ~10, 'id'
         12        SEND_VAL_EX                                              ~11
         13        DO_FCALL                                      0  $12     
         14        BOOL_NOT                                         ~13     $12
         15      > JMPZ                                                     ~13, ->24
    7    16    >   INIT_METHOD_CALL                                         !0, 'push'
         17        FETCH_OBJ_R                                      ~14     !2, 'product_id'
         18        INIT_ARRAY                                       ~15     ~14, 'id'
         19        FETCH_OBJ_R                                      ~16     !2, 'product_qty'
         20        ADD_ARRAY_ELEMENT                                ~15     ~16, 'count'
         21        SEND_VAL_EX                                              ~15
         22        DO_FCALL                                      0          
    6    23      > JMP                                                      ->33
   10    24    > > FE_RESET_RW                                      $18     !0, ->32
         25    > > FE_FETCH_RW                                              $18, !3, ->32
   11    26    >   FETCH_DIM_R                                      ~19     !3, 'id'
         27        FETCH_DIM_R                                      ~20     !1, 'id'
         28        IS_EQUAL                                                 ~19, ~20
         29      > JMPZ                                                     ~21, ->31
   12    30    >   ASSIGN                                                   !3, !1
   10    31    > > JMP                                                      ->25
         32    >   FE_FREE                                                  $18
   15    33    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.74 ms | 1008 KiB | 13 Q