3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data[0] = (object) array( 'time' => '1403071646', 'netin' => '17.75', 'netout' => '22.5' ); $data[1] = (object) array( 'time' => '1403071647', 'netin' => '17.75', 'netout' => '22.5' ); $data[2] = (object) array( 'time' => '1403071649', 'netin' => '17.75', 'netout' => '22.5' ); // trying to make lines 15-19 become the following: // $output .= "{'x':'".date('Y-m-d H:i:s', $stat->time)."','y':'".number_format(round($stat->netin) / 1024, 2)."','z':'".number_format(round($stat->netout) / 1024, 2)."'}"; function chart_data($data, $items) { $count = count($data); $i = 1; $output = ''; foreach ($data as $stat) { $output .= '{'; foreach ($items as $key => $func) { $output .= "'".$key."':'".$func($stat)."'"; } $output .= '}'; if ($i < $count) { $output .= ","; } $output .= "\n"; $i++; } echo $output; } $items = array( 'x' => function ($stat) { return date('Y-m-d H:i:s', $stat->time); }, 'y' => function ($stat) { return number_format(round($stat->netin) / 1024, 2); }, 'z' => function ($stat) { return number_format(round($stat->netout) / 1024, 2); } ); chart_data($data, $items);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hKSTW
function name:  (null)
number of ops:  21
compiled vars:  !0 = $data, !1 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   CAST                                          8  ~3      <array>
          1        ASSIGN_DIM                                               !0, 0
          2        OP_DATA                                                  ~3
    4     3        CAST                                          8  ~5      <array>
          4        ASSIGN_DIM                                               !0, 1
          5        OP_DATA                                                  ~5
    5     6        CAST                                          8  ~7      <array>
          7        ASSIGN_DIM                                               !0, 2
          8        OP_DATA                                                  ~7
   33     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhKSTW%3A33%240'
   35    10        INIT_ARRAY                                       ~9      ~8, 'x'
   36    11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhKSTW%3A36%241'
   38    12        ADD_ARRAY_ELEMENT                                ~9      ~10, 'y'
   39    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhKSTW%3A39%242'
   41    14        ADD_ARRAY_ELEMENT                                ~9      ~11, 'z'
   33    15        ASSIGN                                                   !1, ~9
   45    16        INIT_FCALL                                               'chart_data'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0          
         20      > RETURN                                                   1

Function chart_data:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 29
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 29
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
Branch analysis from position: 21
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/hKSTW
function name:  chart_data
number of ops:  32
compiled vars:  !0 = $data, !1 = $items, !2 = $count, !3 = $i, !4 = $output, !5 = $stat, !6 = $func, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        COUNT                                            ~8      !0
          3        ASSIGN                                                   !2, ~8
   13     4        ASSIGN                                                   !3, 1
   15     5        ASSIGN                                                   !4, ''
   17     6      > FE_RESET_R                                       $12     !0, ->29
          7    > > FE_FETCH_R                                               $12, !5, ->29
   18     8    >   ASSIGN_OP                                     8          !4, '%7B'
   19     9      > FE_RESET_R                                       $14     !1, ->21
         10    > > FE_FETCH_R                                       ~15     $14, !6, ->21
         11    >   ASSIGN                                                   !7, ~15
   20    12        CONCAT                                           ~17     '%27', !7
         13        CONCAT                                           ~18     ~17, '%27%3A%27'
         14        INIT_DYNAMIC_CALL                                        !6
         15        SEND_VAR_EX                                              !5
         16        DO_FCALL                                      0  $19     
         17        CONCAT                                           ~20     ~18, $19
         18        CONCAT                                           ~21     ~20, '%27'
         19        ASSIGN_OP                                     8          !4, ~21
   19    20      > JMP                                                      ->10
         21    >   FE_FREE                                                  $14
   22    22        ASSIGN_OP                                     8          !4, '%7D'
   23    23        IS_SMALLER                                               !3, !2
         24      > JMPZ                                                     ~24, ->26
   24    25    >   ASSIGN_OP                                     8          !4, '%2C'
   26    26    >   ASSIGN_OP                                     8          !4, '%0A'
   27    27        PRE_INC                                                  !3
   17    28      > JMP                                                      ->7
         29    >   FE_FREE                                                  $12
   30    30        ECHO                                                     !4
   31    31      > RETURN                                                   null

End of function chart_data

Function %00%7Bclosure%7D%2Fin%2FhKSTW%3A33%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hKSTW
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $stat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'Y-m-d+H%3Ai%3As'
          3        FETCH_OBJ_R                                      ~1      !0, 'time'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
   35     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhKSTW%3A33%240

Function %00%7Bclosure%7D%2Fin%2FhKSTW%3A36%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hKSTW
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $stat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        INIT_FCALL                                               'number_format'
          2        INIT_FCALL                                               'round'
          3        FETCH_OBJ_R                                      ~1      !0, 'netin'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        DIV                                              ~3      $2, 1024
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 2
          9        DO_ICALL                                         $4      
         10      > RETURN                                                   $4
   38    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhKSTW%3A36%241

Function %00%7Bclosure%7D%2Fin%2FhKSTW%3A39%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hKSTW
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $stat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        INIT_FCALL                                               'number_format'
          2        INIT_FCALL                                               'round'
          3        FETCH_OBJ_R                                      ~1      !0, 'netout'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        DIV                                              ~3      $2, 1024
          7        SEND_VAL                                                 ~3
          8        SEND_VAL                                                 2
          9        DO_ICALL                                         $4      
         10      > RETURN                                                   $4
   41    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhKSTW%3A39%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.54 ms | 1407 KiB | 20 Q