3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $sql = array(array('id' => 0, 'nom' => 'A', 'temp' => 1.1, 'autre' => 0), array('id' => 1, 'nom' => 'A', 'temp' => 2.1, 'autre' => 10), array('id' => 2, 'nom' => 'A', 'temp' => 3.1, 'autre' => 20), array('id' => 3, 'nom' => 'B', 'temp' => 4.1, 'autre' => 30), array('id' => 4, 'nom' => 'C', 'temp' => 5.1, 'autre' => 40), array('id' => 5, 'nom' => 'B', 'temp' => 6.1, 'autre' => 50), array('id' => 6, 'nom' => 'A', 'temp' => 7.1, 'autre' => 60)); $final = array(); foreach($sql as $s) { if( !isset($final[0]) ) { array_push($final, array($s['nom'])); array_push($final[0]['data'], $s['temp']); array_push($final[0]['name'], $s['id']); } } /* if(!isset($final[$i]['data'])) { $final[$i]['data'] = array(); } array_push($final[$i]['data'], $s['temp']); if(!isset($final[$i]['name'])) $final[$i]['name'] = $s['id']; } else { $i = array_search($s['nom'], $final); if(!isset($final[$i]['data'])) { $final[$i]['data'] = array(); } array_push($final[$i]['data'], $s['temp']); } } */ print_r($final);
Output for 5.3.0 - 7.1.0
Warning: array_push() expects parameter 1 to be array, null given in /in/BYeiP on line 18 Warning: array_push() expects parameter 1 to be array, null given in /in/BYeiP on line 19 Array ( [0] => Array ( [0] => A [data] => [name] => ) )
Output for 4.3.2 - 5.2.17
Warning: array_push(): First argument should be an array in /in/BYeiP on line 18 Warning: array_push(): First argument should be an array in /in/BYeiP on line 19 Array ( [0] => Array ( [0] => A [data] => [name] => ) )
Output for 4.3.0 - 4.3.1
Warning: array_push() [http://www.php.net/function.array-push]: First argument should be an array in /in/BYeiP on line 18 Warning: array_push() [http://www.php.net/function.array-push]: First argument should be an array in /in/BYeiP on line 19 Array ( [0] => Array ( [0] => A [data] => [name] => ) )