3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $filtered_decoded[0]['data'] = array( array( 'position' => 2, 'date' => '2013-01-02' ), array( 'position' => 3, 'date' => '2013-01-03' ) ); $filtered_decoded[1]['data'] = array( array( 'position' => 8, 'date' => '2013-01-02' ), array( 'position' => 5, 'date' => '2013-01-03' ) ); $converteddatesarray = array(); print_r($filtered_decoded); foreach ($filtered_decoded['data'] as $key => $list) { $converteddatesarray[] = '['.strtotime($list['date']).'000,'.$list['position'].']'; } $test .= '{"name":"'.$name.'","data":['. implode(",",$converteddatesarray).']},'; echo '['.rtrim($test,",").']';
Output for 5.3.0 - 7.1.0
Array ( [0] => Array ( [data] => Array ( [0] => Array ( [position] => 2 [date] => 2013-01-02 ) [1] => Array ( [position] => 3 [date] => 2013-01-03 ) ) ) [1] => Array ( [data] => Array ( [0] => Array ( [position] => 8 [date] => 2013-01-02 ) [1] => Array ( [position] => 5 [date] => 2013-01-03 ) ) ) ) Notice: Undefined index: data in /in/IvcWn on line 29 Warning: Invalid argument supplied for foreach() in /in/IvcWn on line 29 Notice: Undefined variable: name in /in/IvcWn on line 33 Notice: Undefined variable: test in /in/IvcWn on line 33 [{"name":"","data":[]}]
Output for 5.2.1 - 5.2.17
Array ( [0] => Array ( [data] => Array ( [0] => Array ( [position] => 2 [date] => 2013-01-02 ) [1] => Array ( [position] => 3 [date] => 2013-01-03 ) ) ) [1] => Array ( [data] => Array ( [0] => Array ( [position] => 8 [date] => 2013-01-02 ) [1] => Array ( [position] => 5 [date] => 2013-01-03 ) ) ) ) Notice: Undefined index: data in /in/IvcWn on line 29 Warning: Invalid argument supplied for foreach() in /in/IvcWn on line 29 Notice: Undefined variable: name in /in/IvcWn on line 33 Notice: Undefined variable: test in /in/IvcWn on line 33 [{"name":"","data":[]}]
Output for 5.0.4 - 5.2.0
Array ( [0] => Array ( [data] => Array ( [0] => Array ( [position] => 2 [date] => 2013-01-02 ) [1] => Array ( [position] => 3 [date] => 2013-01-03 ) ) ) [1] => Array ( [data] => Array ( [0] => Array ( [position] => 8 [date] => 2013-01-02 ) [1] => Array ( [position] => 5 [date] => 2013-01-03 ) ) ) ) Warning: Invalid argument supplied for foreach() in /in/IvcWn on line 29 Notice: Undefined variable: name in /in/IvcWn on line 33 Notice: Undefined variable: test in /in/IvcWn on line 33 [{"name":"","data":[]}]
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.0.3
Array ( [0] => Array ( [data] => Array ( [0] => Array ( [position] => 2 [date] => 2013-01-02 ) [1] => Array ( [position] => 3 [date] => 2013-01-03 ) ) ) [1] => Array ( [data] => Array ( [0] => Array ( [position] => 8 [date] => 2013-01-02 ) [1] => Array ( [position] => 5 [date] => 2013-01-03 ) ) ) ) Warning: Invalid argument supplied for foreach() in /in/IvcWn on line 29 Notice: Undefined variable: name in /in/IvcWn on line 33 Notice: Undefined variable: test in /in/IvcWn on line 33 [{"name":"","data":[]}]
Output for 4.3.11
Array ( [0] => Array ( [data] => Array ( [0] => Array ( [position] => 2 [date] => 2013-01-02 ) [1] => Array ( [position] => 3 [date] => 2013-01-03 ) ) ) [1] => Array ( [data] => Array ( [0] => Array ( [position] => 8 [date] => 2013-01-02 ) [1] => Array ( [position] => 5 [date] => 2013-01-03 ) ) ) ) Notice: Undefined variable: name in /in/IvcWn on line 33 Notice: Undefined variable: test in /in/IvcWn on line 33 [{"name":"","data":[]}]