3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = array( array('idproduct' => 1, 'amount' => 5), array('idproduct' => 2, 'amount' => 10), array('idproduct' => 3, 'amount' => 11), array('idproduct' => 4, 'amount' => 5) ); addOrOverride($products, array('idproduct' => 4, 'amount' => 6)); function addOrOverride(&$arr, $newItem) { $filtered = array_filter($arr, function($item) use($newItem) { return $item['idproduct'] == $newItem['idproduct']; }); if(count($filtered) > 0) { $key = key($filtered); $arr[$key] = array_merge($arr[$key], $newItem); } else { $arr[] = $newItem; } } var_dump($products);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EV09b
function name:  (null)
number of ops:  9
compiled vars:  !0 = $products
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    9     1        INIT_FCALL_BY_NAME                                       'addOrOverride'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0          
   24     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function addoroverride:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EV09b
function name:  addOrOverride
number of ops:  27
compiled vars:  !0 = $arr, !1 = $newItem, !2 = $filtered, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'array_filter'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FEV09b%3A12%240'
          5        BIND_LEXICAL                                             ~4, !1
   14     6        SEND_VAL                                                 ~4
          7        DO_ICALL                                         $5      
   12     8        ASSIGN                                                   !2, $5
   16     9        COUNT                                            ~7      !2
         10        IS_SMALLER                                               0, ~7
         11      > JMPZ                                                     ~8, ->24
   17    12    >   INIT_FCALL                                               'key'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !3, $9
   18    16        INIT_FCALL                                               'array_merge'
         17        FETCH_DIM_R                                      ~12     !0, !3
         18        SEND_VAL                                                 ~12
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $13     
         21        ASSIGN_DIM                                               !0, !3
         22        OP_DATA                                                  $13
         23      > JMP                                                      ->26
   20    24    >   ASSIGN_DIM                                               !0
         25        OP_DATA                                                  !1
   22    26    > > RETURN                                                   null

End of function addoroverride

Function %00%7Bclosure%7D%2Fin%2FEV09b%3A12%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EV09b
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $item, !1 = $newItem
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   13     2        FETCH_DIM_R                                      ~2      !0, 'idproduct'
          3        FETCH_DIM_R                                      ~3      !1, 'idproduct'
          4        IS_EQUAL                                         ~4      ~2, ~3
          5      > RETURN                                                   ~4
   14     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FEV09b%3A12%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.46 ms | 1400 KiB | 21 Q