3v4l.org

run code in 300+ PHP versions simultaneously
<?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(array_search($s['nom'], $final) === NULL) array_push($final, $s['nom']); } print_r($final); foreach ($sql as $s) if(in_array($final, $s['nom'])) { if(!isset($final[$s['nom']]['data'])) $final[$s['nom']]['data'] = array(); array_push($final[$s['nom']]['data'], $s['temp']); } else { array_push($final, $s['nom']); if(!isset($final[$s['nom']]['data'])) $final[$s['nom']]['data'] = array(); if(!isset($final[$s['nom']]['nom'])) $final[$s['nom']]['nom'] = $s['id']; array_push($final[$s['nom']]['data'], $s['temp']); } print_r($final);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 16
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 80
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 80
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 47
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 38
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 61
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 71
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 71
Branch analysis from position: 61
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 17
filename:       /in/UDBt7
function name:  (null)
number of ops:  85
compiled vars:  !0 = $sql, !1 = $final, !2 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $5      !0, ->17
          3    > > FE_FETCH_R                                               $5, !2, ->17
   12     4    >   INIT_FCALL                                               'array_search'
          5        FETCH_DIM_R                                      ~6      !2, 'nom'
          6        SEND_VAL                                                 ~6
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        TYPE_CHECK                                    2          $7
         10      > JMPZ                                                     ~8, ->16
   13    11    >   INIT_FCALL                                               'array_push'
         12        SEND_REF                                                 !1
         13        FETCH_DIM_R                                      ~9      !2, 'nom'
         14        SEND_VAL                                                 ~9
         15        DO_ICALL                                                 
   11    16    > > JMP                                                      ->3
         17    >   FE_FREE                                                  $5
   16    18        INIT_FCALL                                               'print_r'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                                 
   18    21      > FE_RESET_R                                       $12     !0, ->80
         22    > > FE_FETCH_R                                               $12, !2, ->80
   19    23    >   INIT_FCALL                                               'in_array'
         24        SEND_VAR                                                 !1
         25        FETCH_DIM_R                                      ~13     !2, 'nom'
         26        SEND_VAL                                                 ~13
         27        DO_ICALL                                         $14     
         28      > JMPZ                                                     $14, ->47
   20    29    >   FETCH_DIM_R                                      ~15     !2, 'nom'
         30        FETCH_DIM_IS                                     ~16     !1, ~15
         31        ISSET_ISEMPTY_DIM_OBJ                         0  ~17     ~16, 'data'
         32        BOOL_NOT                                         ~18     ~17
         33      > JMPZ                                                     ~18, ->38
   21    34    >   FETCH_DIM_R                                      ~19     !2, 'nom'
         35        FETCH_DIM_W                                      $20     !1, ~19
         36        ASSIGN_DIM                                               $20, 'data'
         37        OP_DATA                                                  <array>
   22    38    >   INIT_FCALL                                               'array_push'
         39        FETCH_DIM_R                                      ~22     !2, 'nom'
         40        FETCH_DIM_W                                      $23     !1, ~22
         41        FETCH_DIM_W                                      $24     $23, 'data'
         42        SEND_REF                                                 $24
         43        FETCH_DIM_R                                      ~25     !2, 'temp'
         44        SEND_VAL                                                 ~25
         45        DO_ICALL                                                 
         46      > JMP                                                      ->79
   24    47    >   INIT_FCALL                                               'array_push'
         48        SEND_REF                                                 !1
         49        FETCH_DIM_R                                      ~27     !2, 'nom'
         50        SEND_VAL                                                 ~27
         51        DO_ICALL                                                 
   25    52        FETCH_DIM_R                                      ~29     !2, 'nom'
         53        FETCH_DIM_IS                                     ~30     !1, ~29
         54        ISSET_ISEMPTY_DIM_OBJ                         0  ~31     ~30, 'data'
         55        BOOL_NOT                                         ~32     ~31
         56      > JMPZ                                                     ~32, ->61
   26    57    >   FETCH_DIM_R                                      ~33     !2, 'nom'
         58        FETCH_DIM_W                                      $34     !1, ~33
         59        ASSIGN_DIM                                               $34, 'data'
         60        OP_DATA                                                  <array>
   27    61    >   FETCH_DIM_R                                      ~36     !2, 'nom'
         62        FETCH_DIM_IS                                     ~37     !1, ~36
         63        ISSET_ISEMPTY_DIM_OBJ                         0  ~38     ~37, 'nom'
         64        BOOL_NOT                                         ~39     ~38
         65      > JMPZ                                                     ~39, ->71
   28    66    >   FETCH_DIM_R                                      ~40     !2, 'nom'
         67        FETCH_DIM_R                                      ~43     !2, 'id'
         68        FETCH_DIM_W                                      $41     !1, ~40
         69        ASSIGN_DIM                                               $41, 'nom'
         70        OP_DATA                                                  ~43
   29    71    >   INIT_FCALL                                               'array_push'
         72        FETCH_DIM_R                                      ~44     !2, 'nom'
         73        FETCH_DIM_W                                      $45     !1, ~44
         74        FETCH_DIM_W                                      $46     $45, 'data'
         75        SEND_REF                                                 $46
         76        FETCH_DIM_R                                      ~47     !2, 'temp'
         77        SEND_VAL                                                 ~47
         78        DO_ICALL                                                 
   18    79    > > JMP                                                      ->22
         80    >   FE_FREE                                                  $12
   32    81        INIT_FCALL                                               'print_r'
         82        SEND_VAR                                                 !1
         83        DO_ICALL                                                 
         84      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.12 ms | 1396 KiB | 21 Q