3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr=array( 'ACTION' => 'getsupportdepartments', 'RESULT' => 'success', 'TOTALRESULTS' => 2, 'DEPARTMENTS' => array( 'DEPARTMENT' => array( 'ID' => 2, 'NAME' => 'Sales', 'AWAITINGREPLY' => 5, 'OPENTICKETS' => 5 ), 'DEPARTMENT1' => array( 'ID' => 1, 'NAME' => 'Support', 'AWAITINGREPLY' => 15, 'OPENTICKETS' => 15))); function asc($a,$b) { return $a["AWAITINGREPLY"]-$b["AWAITINGREPLY"]; } function desc($a,$b) { return $b["AWAITINGREPLY"]-$a["AWAITINGREPLY"]; } function sortDepts(array &$arr,$sort="desc") { if($sort=="desc") usort($arr["DEPARTMENTS"],"desc"); else usort($arr["DEPARTMENTS"],"asc"); return $arr; } print_r(sortDepts($arr,"desc")); print_r(sortDepts($arr,"asc"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/909hB
function name:  (null)
number of ops:  16
compiled vars:  !0 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   34     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'sortdepts'
          3        SEND_REF                                                     !0
          4        SEND_VAL                                                     'desc'
          5        DO_FCALL                                          0  $2      
          6        SEND_VAR                                                     $2
          7        DO_ICALL                                                     
   35     8        INIT_FCALL                                                   'print_r'
          9        INIT_FCALL                                                   'sortdepts'
         10        SEND_REF                                                     !0
         11        SEND_VAL                                                     'asc'
         12        DO_FCALL                                          0  $4      
         13        SEND_VAR                                                     $4
         14        DO_ICALL                                                     
         15      > RETURN                                                       1

Function asc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/909hB
function name:  asc
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   20     2        FETCH_DIM_R                                          ~2      !0, 'AWAITINGREPLY'
          3        FETCH_DIM_R                                          ~3      !1, 'AWAITINGREPLY'
          4        SUB                                                  ~4      ~2, ~3
          5      > RETURN                                                       ~4
   21     6*     > RETURN                                                       null

End of function asc

Function desc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/909hB
function name:  desc
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   24     2        FETCH_DIM_R                                          ~2      !1, 'AWAITINGREPLY'
          3        FETCH_DIM_R                                          ~3      !0, 'AWAITINGREPLY'
          4        SUB                                                  ~4      ~2, ~3
          5      > RETURN                                                       ~4
   25     6*     > RETURN                                                       null

End of function desc

Function sortdepts:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/909hB
function name:  sortDepts
number of ops:  17
compiled vars:  !0 = $arr, !1 = $sort
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      'desc'
   28     2        IS_EQUAL                                                     !1, 'desc'
          3      > JMPZ                                                         ~2, ->10
   29     4    >   INIT_FCALL                                                   'usort'
          5        FETCH_DIM_W                                          $3      !0, 'DEPARTMENTS'
          6        SEND_REF                                                     $3
          7        SEND_VAL                                                     'desc'
          8        DO_ICALL                                                     
   28     9      > JMP                                                          ->15
   31    10    >   INIT_FCALL                                                   'usort'
         11        FETCH_DIM_W                                          $5      !0, 'DEPARTMENTS'
         12        SEND_REF                                                     $5
         13        SEND_VAL                                                     'asc'
         14        DO_ICALL                                                     
   32    15    > > RETURN                                                       !0
   33    16*     > RETURN                                                       null

End of function sortdepts

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
179.35 ms | 3873 KiB | 17 Q