3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public $a; public $b; public $c; public function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } $arr = Array( new A('a1235d', 'f', 'M'), new A('a1235d', 'm', 'L'), new A('a1235d', 'm', 'S'), new A('a1234d', 'm', 'L'), new A('a1234d', 'm', 'S'), new A('a1236d', 'm', 'S'), new A('a1236d', 'm', 'M'), new A('a1234d', 'f', 'S'), new A('a1236d', 'f', 'S'), new A('a1236d', 'f', 'M'), new A('a1235d', 'f', 'S'), new A('a1234d', 'm', 'M'), new A('a1235d', 'm', 'M'), new A('a1234d', 'f', 'M'), new A('a1235d', 'f', 'L'), new A('a1236d', 'm', 'L'), new A('a1236d', 'f', 'L'), new A('a1234d', 'f', 'L') ); function sort_by_a($arr) { usort($arr, function($a, $b) { if ($a->a == $b->a) { return 0; } return strcmp($a->a, $b->a); }); return $arr; } function sort_by_b($arr) { usort($arr, function($a, $b) { if ($a->b == $b->b) { return 0; } return strcmp($a->b, $b->b); }); return $arr; } function sort_by_c($arr) { usort($arr, function($a, $b) { if ($a->c == $b->c) { return 0; } return strcmp($a->c, $b->c); }); return $arr; } function printarr($arr) { foreach ($arr as $a) echo $a->a."\t".$a->b."\t".$a->c."\n"; echo "\n"; } $sort = array(); foreach ($arr as $k => $v) { $sort['a'][$k] = $v['a']; $sort['b'][$k] = $v['b']; $sort['c'][$k] = $v['c']; } array_multisort($sort['a'], SORT_DESC, $sort['b'], SORT_DESC, $sort['c'], SORT_DESC, $arr); printarr($arr); //$arr = sort_by_c($arr); //printarr($arr); //$arr = sort_by_b($arr); //printarr($arr); //$arr = sort_by_a($arr); //printarr($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 111, Position 2 = 126
Branch analysis from position: 111
2 jumps found. (Code = 78) Position 1 = 112, Position 2 = 126
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
Branch analysis from position: 126
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 126
filename:       /in/SClMu
function name:  (null)
number of ops:  143
compiled vars:  !0 = $arr, !1 = $sort, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $4      'A'
          1        SEND_VAL_EX                                              'a1235d'
          2        SEND_VAL_EX                                              'f'
          3        SEND_VAL_EX                                              'M'
          4        DO_FCALL                                      0          
          5        INIT_ARRAY                                       ~6      $4
   16     6        NEW                                              $7      'A'
          7        SEND_VAL_EX                                              'a1235d'
          8        SEND_VAL_EX                                              'm'
          9        SEND_VAL_EX                                              'L'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~6      $7
   17    12        NEW                                              $9      'A'
         13        SEND_VAL_EX                                              'a1235d'
         14        SEND_VAL_EX                                              'm'
         15        SEND_VAL_EX                                              'S'
         16        DO_FCALL                                      0          
         17        ADD_ARRAY_ELEMENT                                ~6      $9
   18    18        NEW                                              $11     'A'
         19        SEND_VAL_EX                                              'a1234d'
         20        SEND_VAL_EX                                              'm'
         21        SEND_VAL_EX                                              'L'
         22        DO_FCALL                                      0          
         23        ADD_ARRAY_ELEMENT                                ~6      $11
   19    24        NEW                                              $13     'A'
         25        SEND_VAL_EX                                              'a1234d'
         26        SEND_VAL_EX                                              'm'
         27        SEND_VAL_EX                                              'S'
         28        DO_FCALL                                      0          
         29        ADD_ARRAY_ELEMENT                                ~6      $13
   20    30        NEW                                              $15     'A'
         31        SEND_VAL_EX                                              'a1236d'
         32        SEND_VAL_EX                                              'm'
         33        SEND_VAL_EX                                              'S'
         34        DO_FCALL                                      0          
         35        ADD_ARRAY_ELEMENT                                ~6      $15
   21    36        NEW                                              $17     'A'
         37        SEND_VAL_EX                                              'a1236d'
         38        SEND_VAL_EX                                              'm'
         39        SEND_VAL_EX                                              'M'
         40        DO_FCALL                                      0          
         41        ADD_ARRAY_ELEMENT                                ~6      $17
   22    42        NEW                                              $19     'A'
         43        SEND_VAL_EX                                              'a1234d'
         44        SEND_VAL_EX                                              'f'
         45        SEND_VAL_EX                                              'S'
         46        DO_FCALL                                      0          
         47        ADD_ARRAY_ELEMENT                                ~6      $19
   23    48        NEW                                              $21     'A'
         49        SEND_VAL_EX                                              'a1236d'
         50        SEND_VAL_EX                                              'f'
         51        SEND_VAL_EX                                              'S'
         52        DO_FCALL                                      0          
         53        ADD_ARRAY_ELEMENT                                ~6      $21
   24    54        NEW                                              $23     'A'
         55        SEND_VAL_EX                                              'a1236d'
         56        SEND_VAL_EX                                              'f'
         57        SEND_VAL_EX                                              'M'
         58        DO_FCALL                                      0          
         59        ADD_ARRAY_ELEMENT                                ~6      $23
   25    60        NEW                                              $25     'A'
         61        SEND_VAL_EX                                              'a1235d'
         62        SEND_VAL_EX                                              'f'
         63        SEND_VAL_EX                                              'S'
         64        DO_FCALL                                      0          
         65        ADD_ARRAY_ELEMENT                                ~6      $25
   26    66        NEW                                              $27     'A'
         67        SEND_VAL_EX                                              'a1234d'
         68        SEND_VAL_EX                                              'm'
         69        SEND_VAL_EX                                              'M'
         70        DO_FCALL                                      0          
         71        ADD_ARRAY_ELEMENT                                ~6      $27
   27    72        NEW                                              $29     'A'
         73        SEND_VAL_EX                                              'a1235d'
         74        SEND_VAL_EX                                              'm'
         75        SEND_VAL_EX                                              'M'
         76        DO_FCALL                                      0          
         77        ADD_ARRAY_ELEMENT                                ~6      $29
   28    78        NEW                                              $31     'A'
         79        SEND_VAL_EX                                              'a1234d'
         80        SEND_VAL_EX                                              'f'
         81        SEND_VAL_EX                                              'M'
         82        DO_FCALL                                      0          
         83        ADD_ARRAY_ELEMENT                                ~6      $31
   29    84        NEW                                              $33     'A'
         85        SEND_VAL_EX                                              'a1235d'
         86        SEND_VAL_EX                                              'f'
         87        SEND_VAL_EX                                              'L'
         88        DO_FCALL                                      0          
         89        ADD_ARRAY_ELEMENT                                ~6      $33
   30    90        NEW                                              $35     'A'
         91        SEND_VAL_EX                                              'a1236d'
         92        SEND_VAL_EX                                              'm'
         93        SEND_VAL_EX                                              'L'
         94        DO_FCALL                                      0          
         95        ADD_ARRAY_ELEMENT                                ~6      $35
   31    96        NEW                                              $37     'A'
         97        SEND_VAL_EX                                              'a1236d'
         98        SEND_VAL_EX                                              'f'
         99        SEND_VAL_EX                                              'L'
        100        DO_FCALL                                      0          
        101        ADD_ARRAY_ELEMENT                                ~6      $37
   32   102        NEW                                              $39     'A'
        103        SEND_VAL_EX                                              'a1234d'
        104        SEND_VAL_EX                                              'f'
        105        SEND_VAL_EX                                              'L'
        106        DO_FCALL                                      0          
        107        ADD_ARRAY_ELEMENT                                ~6      $39
   14   108        ASSIGN                                                   !0, ~6
   71   109        ASSIGN                                                   !1, <array>
   72   110      > FE_RESET_R                                       $43     !0, ->126
        111    > > FE_FETCH_R                                       ~44     $43, !2, ->126
        112    >   ASSIGN                                                   !3, ~44
   73   113        FETCH_DIM_R                                      ~48     !2, 'a'
        114        FETCH_DIM_W                                      $46     !1, 'a'
        115        ASSIGN_DIM                                               $46, !3
        116        OP_DATA                                                  ~48
   74   117        FETCH_DIM_R                                      ~51     !2, 'b'
        118        FETCH_DIM_W                                      $49     !1, 'b'
        119        ASSIGN_DIM                                               $49, !3
        120        OP_DATA                                                  ~51
   75   121        FETCH_DIM_R                                      ~54     !2, 'c'
        122        FETCH_DIM_W                                      $52     !1, 'c'
        123        ASSIGN_DIM                                               $52, !3
        124        OP_DATA                                                  ~54
   72   125      > JMP                                                      ->111
        126    >   FE_FREE                                                  $43
   77   127        INIT_FCALL                                               'array_multisort'
        128        FETCH_DIM_W                                      $55     !1, 'a'
        129        SEND_REF                                                 $55
        130        SEND_VAL                                                 3
        131        FETCH_DIM_W                                      $56     !1, 'b'
        132        SEND_REF                                                 $56
        133        SEND_VAL                                                 3
        134        FETCH_DIM_W                                      $57     !1, 'c'
        135        SEND_REF                                                 $57
        136        SEND_VAL                                                 3
        137        SEND_REF                                                 !0
        138        DO_ICALL                                                 
   79   139        INIT_FCALL                                               'printarr'
        140        SEND_VAR                                                 !0
        141        DO_FCALL                                      0          
   85   142      > RETURN                                                   1

Function sort_by_a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  sort_by_a
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        INIT_FCALL                                               'usort'
          2        SEND_REF                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSClMu%3A36%240'
   41     4        SEND_VAL                                                 ~1
          5        DO_ICALL                                                 
   42     6      > RETURN                                                   !0
   43     7*     > RETURN                                                   null

End of function sort_by_a

Function %00%7Bclosure%7D%2Fin%2FSClMu%3A36%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2        FETCH_OBJ_R                                      ~2      !0, 'a'
          3        FETCH_OBJ_R                                      ~3      !1, 'a'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   38     6    > > RETURN                                                   0
   40     7    >   INIT_FCALL                                               'strcmp'
          8        FETCH_OBJ_R                                      ~5      !0, 'a'
          9        SEND_VAL                                                 ~5
         10        FETCH_OBJ_R                                      ~6      !1, 'a'
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13      > RETURN                                                   $7
   41    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSClMu%3A36%240

Function sort_by_b:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  sort_by_b
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
   46     1        INIT_FCALL                                               'usort'
          2        SEND_REF                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSClMu%3A46%241'
   51     4        SEND_VAL                                                 ~1
          5        DO_ICALL                                                 
   52     6      > RETURN                                                   !0
   53     7*     > RETURN                                                   null

End of function sort_by_b

Function %00%7Bclosure%7D%2Fin%2FSClMu%3A46%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   47     2        FETCH_OBJ_R                                      ~2      !0, 'b'
          3        FETCH_OBJ_R                                      ~3      !1, 'b'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   48     6    > > RETURN                                                   0
   50     7    >   INIT_FCALL                                               'strcmp'
          8        FETCH_OBJ_R                                      ~5      !0, 'b'
          9        SEND_VAL                                                 ~5
         10        FETCH_OBJ_R                                      ~6      !1, 'b'
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13      > RETURN                                                   $7
   51    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSClMu%3A46%241

Function sort_by_c:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  sort_by_c
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   56     1        INIT_FCALL                                               'usort'
          2        SEND_REF                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FSClMu%3A56%242'
   61     4        SEND_VAL                                                 ~1
          5        DO_ICALL                                                 
   62     6      > RETURN                                                   !0
   63     7*     > RETURN                                                   null

End of function sort_by_c

Function %00%7Bclosure%7D%2Fin%2FSClMu%3A56%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2        FETCH_OBJ_R                                      ~2      !0, 'c'
          3        FETCH_OBJ_R                                      ~3      !1, 'c'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   58     6    > > RETURN                                                   0
   60     7    >   INIT_FCALL                                               'strcmp'
          8        FETCH_OBJ_R                                      ~5      !0, 'c'
          9        SEND_VAL                                                 ~5
         10        FETCH_OBJ_R                                      ~6      !1, 'c'
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13      > RETURN                                                   $7
   61    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FSClMu%3A56%242

Function printarr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/SClMu
function name:  printarr
number of ops:  16
compiled vars:  !0 = $arr, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
   66     1      > FE_RESET_R                                       $2      !0, ->13
          2    > > FE_FETCH_R                                               $2, !1, ->13
   67     3    >   FETCH_OBJ_R                                      ~3      !1, 'a'
          4        CONCAT                                           ~4      ~3, '%09'
          5        FETCH_OBJ_R                                      ~5      !1, 'b'
          6        CONCAT                                           ~6      ~4, ~5
          7        CONCAT                                           ~7      ~6, '%09'
          8        FETCH_OBJ_R                                      ~8      !1, 'c'
          9        CONCAT                                           ~9      ~7, ~8
         10        CONCAT                                           ~10     ~9, '%0A'
         11        ECHO                                                     ~10
   66    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $2
   68    14        ECHO                                                     '%0A'
   69    15      > RETURN                                                   null

End of function printarr

Class A:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SClMu
function name:  __construct
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    8     3        ASSIGN_OBJ                                               'a'
          4        OP_DATA                                                  !0
    9     5        ASSIGN_OBJ                                               'b'
          6        OP_DATA                                                  !1
   10     7        ASSIGN_OBJ                                               'c'
          8        OP_DATA                                                  !2
   11     9      > RETURN                                                   null

End of function __construct

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.7 ms | 1419 KiB | 20 Q