3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $data[0] = array( 'time' => '1403071646', 'netin' => '17.75', 'netout' => '22.5' ); $data[1] = array( 'time' => '1403071647', 'netin' => '17.75', 'netout' => '22.5' ); $data[2] = 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; 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 - 7.1.0
Notice: Undefined variable: output in /in/SVLDT on line 15 Notice: Trying to get property of non-object in /in/SVLDT on line 31 Notice: Trying to get property of non-object in /in/SVLDT on line 34 Notice: Trying to get property of non-object in /in/SVLDT on line 37 Notice: Trying to get property of non-object in /in/SVLDT on line 31 Notice: Trying to get property of non-object in /in/SVLDT on line 34 Notice: Trying to get property of non-object in /in/SVLDT on line 37 Notice: Trying to get property of non-object in /in/SVLDT on line 31 Notice: Trying to get property of non-object in /in/SVLDT on line 34 Notice: Trying to get property of non-object in /in/SVLDT on line 37 {'x':'1970-01-01 01:00:00''y':'0.00''z':'0.00'}, {'x':'1970-01-01 01:00:00''y':'0.00''z':'0.00'}, {'x':'1970-01-01 01:00:00''y':'0.00''z':'0.00'}
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/SVLDT on line 30
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/SVLDT on line 30
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/SVLDT on line 30
Process exited with code 255.