3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 7867867, 'title' => 'Some Title'], ['id' => 3452342, 'title' => 'Some Title'], ['id' => 'foo', 'title' => 'Some Title'], ['id' => 1231233, 'title' => 'Some Title'], ['id' => 'bar', 'title' => 'Some Title'], ['id' => 5867867, 'title' => 'Some Title'] ]; // restructure with values as keys, and keys as order (ASC) $order = array_flip([3452342, 5867867, 7867867, 1231233]); // generating $order = [3452342 => 0, 5867867 => 1, 7867867 => 2, 1231233 => 3]; $default = count($order); // generating $default = 4 usort($array, function($a, $b) use($order, $default) { return strnatcmp( isset($order[$a['id']]) ? $order[$a['id']] : $default, isset($order[$b['id']]) ? $order[$b['id']] : $default ); }); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oOXBn
function name:  (null)
number of ops:  18
compiled vars:  !0 = $array, !1 = $order, !2 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'array_flip'
          2        SEND_VAL                                                 <array>
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   16     5        COUNT                                            ~6      !1
          6        ASSIGN                                                   !2, ~6
   20     7        INIT_FCALL                                               'usort'
          8        SEND_REF                                                 !0
          9        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
         10        BIND_LEXICAL                                             ~8, !1
         11        BIND_LEXICAL                                             ~8, !2
   25    12        SEND_VAL                                                 ~8
   20    13        DO_ICALL                                                 
   27    14        INIT_FCALL                                               'var_export'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                                 
         17      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
Branch analysis from position: 21
filename:       /in/oOXBn
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $a, !1 = $b, !2 = $order, !3 = $default
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
          3        BIND_STATIC                                              !3
   21     4        INIT_FCALL                                               'strnatcmp'
   22     5        FETCH_DIM_R                                      ~4      !0, 'id'
          6        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~4
          7      > JMPZ                                                     ~5, ->12
          8    >   FETCH_DIM_R                                      ~6      !0, 'id'
          9        FETCH_DIM_R                                      ~7      !2, ~6
         10        QM_ASSIGN                                        ~8      ~7
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~8      !3
         13    >   SEND_VAL                                                 ~8
   23    14        FETCH_DIM_R                                      ~9      !1, 'id'
         15        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~9
         16      > JMPZ                                                     ~10, ->21
         17    >   FETCH_DIM_R                                      ~11     !1, 'id'
         18        FETCH_DIM_R                                      ~12     !2, ~11
         19        QM_ASSIGN                                        ~13     ~12
         20      > JMP                                                      ->22
         21    >   QM_ASSIGN                                        ~13     !3
         22    >   SEND_VAL                                                 ~13
   21    23        DO_ICALL                                         $14     
   23    24      > RETURN                                                   $14
   25    25*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.88 ms | 1008 KiB | 17 Q