3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{ "rate":{ "items":[ { "name":"My Product 3", "sku":null, "quantity":1, "grams":1000, "price":2000, "vendor":"TestVendor", "requires_shipping":true, "taxable":true, "fulfillment_service":"manual" }, { "name":"My Product 1", "sku":null, "quantity":1, "grams":500, "price":1000, "vendor":"TestVendor", "requires_shipping":true, "taxable":true, "fulfillment_service":"manual" }, { "name":"My Product 2", "sku":null, "quantity":1, "grams":2000, "price":3000, "vendor":"TestVendor", "requires_shipping":true, "taxable":true, "fulfillment_service":"manual" } ], "currency":"CAD" }}'; $array = json_decode($json, true); var_export( array_sum( array_column( $array['rate']['items'], 'grams' ) ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UkACM
function name:  (null)
number of ops:  19
compiled vars:  !0 = $json, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B+%22rate%22%3A%7B+%22items%22%3A%5B+%7B+%22name%22%3A%22My+Product+3%22%2C+%22sku%22%3Anull%2C+%22quantity%22%3A1%2C+%22grams%22%3A1000%2C+%22price%22%3A2000%2C+%22vendor%22%3A%22TestVendor%22%2C+%22requires_shipping%22%3Atrue%2C+%22taxable%22%3Atrue%2C+%22fulfillment_service%22%3A%22manual%22+%7D%2C+%7B+%22name%22%3A%22My+Product+1%22%2C+%22sku%22%3Anull%2C+%22quantity%22%3A1%2C+%22grams%22%3A500%2C+%22price%22%3A1000%2C+%22vendor%22%3A%22TestVendor%22%2C+%22requires_shipping%22%3Atrue%2C+%22taxable%22%3Atrue%2C+%22fulfillment_service%22%3A%22manual%22+%7D%2C+%7B+%22name%22%3A%22My+Product+2%22%2C+%22sku%22%3Anull%2C+%22quantity%22%3A1%2C+%22grams%22%3A2000%2C+%22price%22%3A3000%2C+%22vendor%22%3A%22TestVendor%22%2C+%22requires_shipping%22%3Atrue%2C+%22taxable%22%3Atrue%2C+%22fulfillment_service%22%3A%22manual%22+%7D+%5D%2C+%22currency%22%3A%22CAD%22+%7D%7D'
    4     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
    5     6        INIT_FCALL                                               'var_export'
    6     7        INIT_FCALL                                               'array_sum'
    7     8        INIT_FCALL                                               'array_column'
    8     9        FETCH_DIM_R                                      ~5      !1, 'rate'
         10        FETCH_DIM_R                                      ~6      ~5, 'items'
         11        SEND_VAL                                                 ~6
    9    12        SEND_VAL                                                 'grams'
    7    13        DO_ICALL                                         $7      
    9    14        SEND_VAR                                                 $7
    6    15        DO_ICALL                                         $8      
    9    16        SEND_VAR                                                 $8
    5    17        DO_ICALL                                                 
   12    18      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
245.07 ms | 1008 KiB | 17 Q