3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cars = array ( 0 => (object)(array( 'id' => 1, 'title' => 'Golf', 'manufacturer' => 1 )), 1 => (object)(array( 'id' => 2, 'title' => 'Focus', 'manufacturer' => 2 )), 2 => (object)(array( 'id' => 3, 'title' => 'Jazz', 'manufacturer' => null )), 3 => (object)(array( 'id' => 4, 'title' => 'Passat', 'manufacturer' => 1 )), 4 => (object)(array( 'id' => 5, 'title' => 'Toureg', 'manufacturer' => 1 )), 5 => (object)(array( 'id' => 6, 'title' => 'Galaxy', 'manufacturer' => 2 )), 6 => (object)(array( 'id' => 7, 'title' => 'Falcon', 'manufacturer' => null )), 7 => (object)(array( 'id' => 8, 'title' => 'Commodore', 'manufacturer' => null )), 8 => (object)(array( 'id' => 9, 'title' => 'Phoenix', 'manufacturer' => 3 )), 9 => (object)(array( 'id' => 10, 'title' => 'Cressida', 'manufacturer' => null )) ); // sort based on manufacturer usort($cars, function ($a, $b) { if (!$a->manufacturer) { // if both null, sort by id if (!$b->manufacturer) return $a->id - $b->id; // otherwise sort null values last return 1; } if (!$b->manufacturer) // sort null values last return -1; return $a->manufacturer - $b->manufacturer; }); $lastmfg = 0; foreach ($cars as $car) { if (!$car->manufacturer || $car->manufacturer != $lastmfg) { if ($lastmfg !== 0) echo "</div>\n"; echo '<div class="container'. ($car->manufacturer ? ' id' . $car->manufacturer : '') .'">'. "\n"; } echo 'ID: ' . $car->id . ' - ' . $car->title . "\n"; $lastmfg = $car->manufacturer; } echo "</div>\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 60
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 60
Branch analysis from position: 29
2 jumps found. (Code = 47) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 50
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 39
Branch analysis from position: 50
Branch analysis from position: 35
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
filename:       /in/nVPGt
function name:  (null)
number of ops:  63
compiled vars:  !0 = $cars, !1 = $lastmfg, !2 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   CAST                                          8  ~3      <array>
          1        INIT_ARRAY                                       ~4      ~3, 0
   12     2        CAST                                          8  ~5      <array>
          3        ADD_ARRAY_ELEMENT                                ~4      ~5, 1
   18     4        CAST                                          8  ~6      <array>
          5        ADD_ARRAY_ELEMENT                                ~4      ~6, 2
   24     6        CAST                                          8  ~7      <array>
          7        ADD_ARRAY_ELEMENT                                ~4      ~7, 3
   30     8        CAST                                          8  ~8      <array>
          9        ADD_ARRAY_ELEMENT                                ~4      ~8, 4
   36    10        CAST                                          8  ~9      <array>
         11        ADD_ARRAY_ELEMENT                                ~4      ~9, 5
   42    12        CAST                                          8  ~10     <array>
         13        ADD_ARRAY_ELEMENT                                ~4      ~10, 6
   48    14        CAST                                          8  ~11     <array>
         15        ADD_ARRAY_ELEMENT                                ~4      ~11, 7
   54    16        CAST                                          8  ~12     <array>
         17        ADD_ARRAY_ELEMENT                                ~4      ~12, 8
   60    18        CAST                                          8  ~13     <array>
         19        ADD_ARRAY_ELEMENT                                ~4      ~13, 9
    3    20        ASSIGN                                                   !0, ~4
   68    21        INIT_FCALL                                               'usort'
         22        SEND_REF                                                 !0
         23        DECLARE_LAMBDA_FUNCTION                          ~15     [0]
   79    24        SEND_VAL                                                 ~15
   68    25        DO_ICALL                                                 
   81    26        ASSIGN                                                   !1, 0
   82    27      > FE_RESET_R                                       $18     !0, ->60
         28    > > FE_FETCH_R                                               $18, !2, ->60
   83    29    >   FETCH_OBJ_R                                      ~19     !2, 'manufacturer'
         30        BOOL_NOT                                         ~20     ~19
         31      > JMPNZ_EX                                         ~20     ~20, ->35
         32    >   FETCH_OBJ_R                                      ~21     !2, 'manufacturer'
         33        IS_NOT_EQUAL                                     ~22     !1, ~21
         34        BOOL                                             ~20     ~22
         35    > > JMPZ                                                     ~20, ->50
   84    36    >   IS_NOT_IDENTICAL                                         !1, 0
         37      > JMPZ                                                     ~23, ->39
         38    >   ECHO                                                     '%3C%2Fdiv%3E%0A'
   85    39    >   FETCH_OBJ_R                                      ~24     !2, 'manufacturer'
         40      > JMPZ                                                     ~24, ->45
         41    >   FETCH_OBJ_R                                      ~25     !2, 'manufacturer'
         42        CONCAT                                           ~26     '+id', ~25
         43        QM_ASSIGN                                        ~27     ~26
         44      > JMP                                                      ->46
         45    >   QM_ASSIGN                                        ~27     ''
         46    >   CONCAT                                           ~28     '%3Cdiv+class%3D%22container', ~27
         47        CONCAT                                           ~29     ~28, '%22%3E'
         48        CONCAT                                           ~30     ~29, '%0A'
         49        ECHO                                                     ~30
   87    50    >   FETCH_OBJ_R                                      ~31     !2, 'id'
         51        CONCAT                                           ~32     'ID%3A+', ~31
         52        CONCAT                                           ~33     ~32, '+-+'
         53        FETCH_OBJ_R                                      ~34     !2, 'title'
         54        CONCAT                                           ~35     ~33, ~34
         55        CONCAT                                           ~36     ~35, '%0A'
         56        ECHO                                                     ~36
   88    57        FETCH_OBJ_R                                      ~37     !2, 'manufacturer'
         58        ASSIGN                                                   !1, ~37
   82    59      > JMP                                                      ->28
         60    >   FE_FREE                                                  $18
   90    61        ECHO                                                     '%3C%2Fdiv%3E%0A'
         62      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nVPGt
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   69     2        FETCH_OBJ_R                                      ~2      !0, 'manufacturer'
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->13
   71     5    >   FETCH_OBJ_R                                      ~4      !1, 'manufacturer'
          6        BOOL_NOT                                         ~5      ~4
          7      > JMPZ                                                     ~5, ->12
          8    >   FETCH_OBJ_R                                      ~6      !0, 'id'
          9        FETCH_OBJ_R                                      ~7      !1, 'id'
         10        SUB                                              ~8      ~6, ~7
         11      > RETURN                                                   ~8
   73    12    > > RETURN                                                   1
   75    13    >   FETCH_OBJ_R                                      ~9      !1, 'manufacturer'
         14        BOOL_NOT                                         ~10     ~9
         15      > JMPZ                                                     ~10, ->17
   77    16    > > RETURN                                                   -1
   78    17    >   FETCH_OBJ_R                                      ~11     !0, 'manufacturer'
         18        FETCH_OBJ_R                                      ~12     !1, 'manufacturer'
         19        SUB                                              ~13     ~11, ~12
         20      > RETURN                                                   ~13
   79    21*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.08 ms | 1454 KiB | 14 Q