3v4l.org

run code in 300+ PHP versions simultaneously
<?php $aO = new ArrayObject(); $aO['3'] = (object)['sortKey'=>8, 'label'=>'three']; $aO['1'] = (object)['sortKey'=>6, 'label'=>'one']; $aO['a'] = (object)['sortKey'=>4, 'label'=>'Letter A']; $output = applyOrder($aO, ['sortKey'=>'ASC']); var_dump($output); function applyOrder(array $resources, array $orderBy) { $results = $resources; foreach ($orderBy as $property => $order) { $sortable = []; foreach ($results as $key => $object) { $sortable[$key] = $object->$property; if (null === $sortable[$key]) { unset($sortable[$key]); } } if ('ASC' === $order) { asort($sortable); } elseif ('DESC' === $order) { arsort($sortable); } $results = []; foreach ($sortable as $key => $propertyValue) { $results[$key] = $resources[$key]; } } return $results; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FGvLB
function name:  (null)
number of ops:  21
compiled vars:  !0 = $aO, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $2      'ArrayObject'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
    5     3        CAST                                          8  ~6      <array>
          4        ASSIGN_DIM                                               !0, 3
          5        OP_DATA                                                  ~6
    6     6        CAST                                          8  ~8      <array>
          7        ASSIGN_DIM                                               !0, 1
          8        OP_DATA                                                  ~8
    7     9        CAST                                          8  ~10     <array>
         10        ASSIGN_DIM                                               !0, 'a'
         11        OP_DATA                                                  ~10
    9    12        INIT_FCALL_BY_NAME                                       'applyOrder'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAL_EX                                              <array>
         15        DO_FCALL                                      0  $11     
         16        ASSIGN                                                   !1, $11
   10    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   34    20      > RETURN                                                   1

Function applyorder:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 40
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 38
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
Branch analysis from position: 38
Branch analysis from position: 30
Branch analysis from position: 18
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/FGvLB
function name:  applyOrder
number of ops:  43
compiled vars:  !0 = $resources, !1 = $orderBy, !2 = $results, !3 = $order, !4 = $property, !5 = $sortable, !6 = $object, !7 = $key, !8 = $propertyValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        ASSIGN                                                   !2, !0
   15     3      > FE_RESET_R                                       $10     !1, ->40
          4    > > FE_FETCH_R                                       ~11     $10, !3, ->40
          5    >   ASSIGN                                                   !4, ~11
   16     6        ASSIGN                                                   !5, <array>
   17     7      > FE_RESET_R                                       $14     !2, ->18
          8    > > FE_FETCH_R                                       ~15     $14, !6, ->18
          9    >   ASSIGN                                                   !7, ~15
   18    10        FETCH_OBJ_R                                      ~18     !6, !4
         11        ASSIGN_DIM                                               !5, !7
         12        OP_DATA                                                  ~18
   19    13        FETCH_DIM_R                                      ~19     !5, !7
         14        TYPE_CHECK                                    2          ~19
         15      > JMPZ                                                     ~20, ->17
   20    16    >   UNSET_DIM                                                !5, !7
   17    17    > > JMP                                                      ->8
         18    >   FE_FREE                                                  $14
   23    19        IS_IDENTICAL                                             !3, 'ASC'
         20      > JMPZ                                                     ~21, ->25
   24    21    >   INIT_FCALL                                               'asort'
         22        SEND_REF                                                 !5
         23        DO_ICALL                                                 
         24      > JMP                                                      ->30
   25    25    >   IS_IDENTICAL                                             !3, 'DESC'
         26      > JMPZ                                                     ~23, ->30
   26    27    >   INIT_FCALL                                               'arsort'
         28        SEND_REF                                                 !5
         29        DO_ICALL                                                 
   28    30    >   ASSIGN                                                   !2, <array>
   29    31      > FE_RESET_R                                       $26     !5, ->38
         32    > > FE_FETCH_R                                       ~27     $26, !8, ->38
         33    >   ASSIGN                                                   !7, ~27
   30    34        FETCH_DIM_R                                      ~30     !0, !7
         35        ASSIGN_DIM                                               !2, !7
         36        OP_DATA                                                  ~30
   29    37      > JMP                                                      ->32
         38    >   FE_FREE                                                  $26
   15    39      > JMP                                                      ->4
         40    >   FE_FREE                                                  $10
   33    41      > RETURN                                                   !2
   34    42*     > RETURN                                                   null

End of function applyorder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.41 ms | 1400 KiB | 19 Q