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(!in_array($s['nom'], $final)) { array_merge($final[$s['nom']], array('data')); array_merge($final[$s['nom']]['data'], array($s['temp'])); } else array_push($final[$s['nom']]['data'], $s['temp']); print_r($final);
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: C in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: C in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Array ( )
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Warning: array_merge() expects parameter 1 to be array, null given in /in/HRAX8 on line 13 Array ( )
Output for 5.0.0 - 5.2.17
Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: C in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: C in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Warning: array_merge(): Argument #1 is not an array in /in/HRAX8 on line 13 Array ( )
Output for 4.3.0 - 4.4.9
Notice: Undefined index: A in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Notice: Undefined index: C in /in/HRAX8 on line 12 Notice: Undefined index: C in /in/HRAX8 on line 13 Notice: Undefined index: B in /in/HRAX8 on line 12 Notice: Undefined index: B in /in/HRAX8 on line 13 Notice: Undefined index: A in /in/HRAX8 on line 12 Notice: Undefined index: A in /in/HRAX8 on line 13 Array ( )