3v4l.org

run code in 300+ 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 sortDepts(array &$arr,$sort="desc") { function asc($a,$b) { return $a["AWAITINGREPLY"]-$b["AWAITINGREPLY"]; } function desc($a,$b) { return $b["AWAITINGREPLY"]-$a["AWAITINGREPLY"]; } 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/1sec6
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 sortdepts:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1sec6
function name:  sortDepts
number of ops:  19
compiled vars:  !0 = $arr, !1 = $sort
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'desc'
   20     2        DECLARE_FUNCTION                                         'asc'
   24     3        DECLARE_FUNCTION                                         'desc'
   28     4        IS_EQUAL                                                 !1, 'desc'
          5      > JMPZ                                                     ~2, ->12
   29     6    >   INIT_FCALL                                               'usort'
          7        FETCH_DIM_W                                      $3      !0, 'DEPARTMENTS'
          8        SEND_REF                                                 $3
          9        SEND_VAL                                                 'desc'
         10        DO_ICALL                                                 
         11      > JMP                                                      ->17
   31    12    >   INIT_FCALL                                               'usort'
         13        FETCH_DIM_W                                      $5      !0, 'DEPARTMENTS'
         14        SEND_REF                                                 $5
         15        SEND_VAL                                                 'asc'
         16        DO_ICALL                                                 
   32    17    > > RETURN                                                   !0
   33    18*     > RETURN                                                   null

End of function sortdepts

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

End of function %00asc%2Fin%2F1sec6%3A20%240

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

End of function %00desc%2Fin%2F1sec6%3A24%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.07 ms | 1403 KiB | 19 Q