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);
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
{'x':'2014-06-18 08:07:26''y':'0.02''z':'0.02'}, {'x':'2014-06-18 08:07:27''y':'0.02''z':'0.02'}, {'x':'2014-06-18 08:07:29''y':'0.02''z':'0.02'}
Output for 7.3.32 - 7.3.33, 7.4.26, 8.0.13
{'x':'2014-06-18 06:07:26''y':'0.02''z':'0.02'}, {'x':'2014-06-18 06:07:27''y':'0.02''z':'0.02'}, {'x':'2014-06-18 06:07:29''y':'0.02''z':'0.02'}
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/hKSTW on line 33
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/hKSTW on line 33
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/hKSTW on line 33
Process exited with code 255.

preferences:
203.33 ms | 401 KiB | 356 Q