3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array=[ (object)['entry_id'=>1,'created_at'=>'2017-04-03','meta_key'=>'Name','meta_value'=>'Smith'], (object)['entry_id'=>1,'created_at'=>'2017-04-03','meta_key'=>'Address','meta_value'=>'Saniply'], (object)['entry_id'=>1,'created_at'=>'2017-04-03','meta_key'=>'Profession','meta_value'=>'Student'], (object)['entry_id'=>2,'created_at'=>'2017-07-05','meta_key'=>'Name','meta_value'=>'John'], (object)['entry_id'=>2,'created_at'=>'2017-07-05','meta_key'=>'Address','meta_value'=>'Aviero'], (object)['entry_id'=>2,'created_at'=>'2017-07-05','meta_key'=>'Profession','meta_value'=>'Businessman'] ]; foreach($array as $obj){ // iterate all objs $id=$obj->entry_id; // cache for more readable code if(!isset($result[$id])){ // first occurrence of entry_id $result[$id]=new \stdClass(); // avoid Warning: Creating default object from empty value $result[$id]->entry_id=$id; // store entry_id $result[$id]->created_at=$obj->created_at; // store created_at } $result[$id]->{$obj->meta_key}=$obj->meta_value; // unconditionally store meta_key and meta_value } var_export(array_values($result)); // remove temporary indexes and display
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 37
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 37
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 31
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/vi27G
function name:  (null)
number of ops:  45
compiled vars:  !0 = $array, !1 = $obj, !2 = $id, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   CAST                                          8  ~4      <array>
          1        INIT_ARRAY                                       ~5      ~4
    4     2        CAST                                          8  ~6      <array>
          3        ADD_ARRAY_ELEMENT                                ~5      ~6
    5     4        CAST                                          8  ~7      <array>
          5        ADD_ARRAY_ELEMENT                                ~5      ~7
    6     6        CAST                                          8  ~8      <array>
          7        ADD_ARRAY_ELEMENT                                ~5      ~8
    7     8        CAST                                          8  ~9      <array>
          9        ADD_ARRAY_ELEMENT                                ~5      ~9
    8    10        CAST                                          8  ~10     <array>
         11        ADD_ARRAY_ELEMENT                                ~5      ~10
    2    12        ASSIGN                                                   !0, ~5
   10    13      > FE_RESET_R                                       $12     !0, ->37
         14    > > FE_FETCH_R                                               $12, !1, ->37
   11    15    >   FETCH_OBJ_R                                      ~13     !1, 'entry_id'
         16        ASSIGN                                                   !2, ~13
   12    17        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !3, !2
         18        BOOL_NOT                                         ~16     ~15
         19      > JMPZ                                                     ~16, ->31
   13    20    >   NEW                                              $18     'stdClass'
         21        DO_FCALL                                      0          
         22        ASSIGN_DIM                                               !3, !2
         23        OP_DATA                                                  $18
   14    24        FETCH_DIM_W                                      $20     !3, !2
         25        ASSIGN_OBJ                                               $20, 'entry_id'
         26        OP_DATA                                                  !2
   15    27        FETCH_OBJ_R                                      ~24     !1, 'created_at'
         28        FETCH_DIM_W                                      $22     !3, !2
         29        ASSIGN_OBJ                                               $22, 'created_at'
         30        OP_DATA                                                  ~24
   17    31    >   FETCH_OBJ_R                                      ~26     !1, 'meta_key'
         32        FETCH_OBJ_R                                      ~28     !1, 'meta_value'
         33        FETCH_DIM_W                                      $25     !3, !2
         34        ASSIGN_OBJ                                               $25, ~26
         35        OP_DATA                                                  ~28
   10    36      > JMP                                                      ->14
         37    >   FE_FREE                                                  $12
   19    38        INIT_FCALL                                               'var_export'
         39        INIT_FCALL                                               'array_values'
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $29     
         42        SEND_VAR                                                 $29
         43        DO_ICALL                                                 
         44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.63 ms | 1008 KiB | 15 Q