3v4l.org

run code in 300+ PHP versions simultaneously
<?php // take the badly formatted JSON $result = '{ "price": [ { "price": "2000", "origin_name": "JPN", }, { "price": "5000", "origin_name": "USA", } ] }'; // and remove the superfluous commas: $pat = "/(o.+),/"; $replace = "$1"; $nu_result = preg_replace($pat,$replace,$result); // now convert JSON into PHP array and traverse it $resultDecoded = json_decode($nu_result, true); $arr = array_pop($resultDecoded); array_walk_recursive($arr,function($e,$i) { if ($i == "price") { echo "price: ",$e,"\n"; } else if ($i == "origin_name") { echo "origin_name: ",$e,"\n\n"; } });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uuNZU
function name:  (null)
number of ops:  24
compiled vars:  !0 = $result, !1 = $pat, !2 = $replace, !3 = $nu_result, !4 = $resultDecoded, !5 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%0A++++++++%22price%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++++%22price%22%3A+%222000%22%2C%0A++++++++++++++++%22origin_name%22%3A+%22JPN%22%2C%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22price%22%3A+%225000%22%2C%0A++++++++++++++++%22origin_name%22%3A+%22USA%22%2C%0A++++++++++++%7D%0A++++++++%5D%0A+++%7D'
   17     1        ASSIGN                                                   !1, '%2F%28o.%2B%29%2C%2F'
   18     2        ASSIGN                                                   !2, '%241'
   19     3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !3, $9
   22     9        INIT_FCALL                                               'json_decode'
         10        SEND_VAR                                                 !3
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $11     
         13        ASSIGN                                                   !4, $11
   23    14        INIT_FCALL                                               'array_pop'
         15        SEND_REF                                                 !4
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !5, $13
   24    18        INIT_FCALL                                               'array_walk_recursive'
         19        SEND_REF                                                 !5
         20        DECLARE_LAMBDA_FUNCTION                          ~15     [0]
   32    21        SEND_VAL                                                 ~15
   24    22        DO_ICALL                                                 
   33    23      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/uuNZU
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $e, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        IS_EQUAL                                                 !1, 'price'
          3      > JMPZ                                                     ~2, ->8
   26     4    >   ECHO                                                     'price%3A+'
          5        ECHO                                                     !0
          6        ECHO                                                     '%0A'
   25     7      > JMP                                                      ->13
   29     8    >   IS_EQUAL                                                 !1, 'origin_name'
          9      > JMPZ                                                     ~3, ->13
   30    10    >   ECHO                                                     'origin_name%3A+'
         11        ECHO                                                     !0
         12        ECHO                                                     '%0A%0A'
   32    13    > > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
276.01 ms | 1010 KiB | 17 Q