3v4l.org

run code in 500+ PHP versions simultaneously
<?php $a = [ 'admin' => [ [ 'id' => 3, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2000-01-01 00:00:00', 'full_link' => 'admin/billing_contacts.app', ], [ 'id' => 1, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-19 13:18:59', 'full_link' => 'admin/billing_contacts.app', ], [ 'id' => 2, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-15 13:18:59', 'full_link' => 'admin/billing_contacts.app', ], ], 'invoice' => [ [ 'id' => 3, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2000-01-01 00:00:00', 'full_link' => 'admin/create_invoice.app', ], [ 'id' => 1, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-19 13:18:59', 'full_link' => 'admin/create_invoice.app', ], [ 'id' => 2, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-20 13:18:59', 'full_link' => 'admin/create_invoice.app', ], ], ]; function customSort(array $array) { // Iterate through and sort second level array by most recent date foreach ($array as $key => &$value) { usort($value, function ($a, $b) { return strtotime($a['latest_user_activity_date']) < strtotime($b['latest_user_activity_date']) ? 1 : -1; }); } // Sort first level array by date descending of first (most recent) entry uasort($array, function ($a, $b) { return strtotime($a[0]['latest_user_activity_date']) < strtotime($b[0]['latest_user_activity_date']) ? 1 : -1; }); return $array; } print_r(customSort($a));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oZvJv
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   59     1        INIT_FCALL                                                   'print_r'
          2        INIT_FCALL                                                   'customsort'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Function customsort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/oZvJv
function name:  customSort
number of ops:  18
compiled vars:  !0 = $array, !1 = $value, !2 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   RECV                                                 !0      
   45     1      > FE_RESET_RW                                          $3      !0, ->10
          2    > > FE_FETCH_RW                                          ~4      $3, !1, ->10
          3    >   ASSIGN                                                       !2, ~4
   46     4        INIT_FCALL                                                   'usort'
          5        SEND_REF                                                     !1
          6        DECLARE_LAMBDA_FUNCTION                              ~6      [0]
   48     7        SEND_VAL                                                     ~6
   46     8        DO_ICALL                                                     
   45     9      > JMP                                                          ->2
         10    >   FE_FREE                                                      $3
   52    11        INIT_FCALL                                                   'uasort'
         12        SEND_REF                                                     !0
         13        DECLARE_LAMBDA_FUNCTION                              ~8      [1]
   54    14        SEND_VAL                                                     ~8
   52    15        DO_ICALL                                                     
   56    16      > RETURN                                                       !0
   57    17*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
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: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oZvJv
function name:  {closure:customSort():46}
number of ops:  17
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        INIT_FCALL                                                   'strtotime'
          3        FETCH_DIM_R                                          ~2      !0, 'latest_user_activity_date'
          4        SEND_VAL                                                     ~2
          5        DO_ICALL                                             $3      
          6        INIT_FCALL                                                   'strtotime'
          7        FETCH_DIM_R                                          ~4      !1, 'latest_user_activity_date'
          8        SEND_VAL                                                     ~4
          9        DO_ICALL                                             $5      
         10        IS_SMALLER                                                   $3, $5
         11      > JMPZ                                                         ~6, ->14
         12    >   QM_ASSIGN                                            ~7      1
         13      > JMP                                                          ->15
         14    >   QM_ASSIGN                                            ~7      -1
         15    > > RETURN                                                       ~7
   48    16*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
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: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oZvJv
function name:  {closure:customSort():52}
number of ops:  19
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   52     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   53     2        INIT_FCALL                                                   'strtotime'
          3        FETCH_DIM_R                                          ~2      !0, 0
          4        FETCH_DIM_R                                          ~3      ~2, 'latest_user_activity_date'
          5        SEND_VAL                                                     ~3
          6        DO_ICALL                                             $4      
          7        INIT_FCALL                                                   'strtotime'
          8        FETCH_DIM_R                                          ~5      !1, 0
          9        FETCH_DIM_R                                          ~6      ~5, 'latest_user_activity_date'
         10        SEND_VAL                                                     ~6
         11        DO_ICALL                                             $7      
         12        IS_SMALLER                                                   $4, $7
         13      > JMPZ                                                         ~8, ->16
         14    >   QM_ASSIGN                                            ~9      1
         15      > JMP                                                          ->17
         16    >   QM_ASSIGN                                            ~9      -1
         17    > > RETURN                                                       ~9
   54    18*     > RETURN                                                       null

End of Dynamic Function 1

End of function customsort

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
232.25 ms | 3131 KiB | 18 Q