3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array( 'keywordid' => 98, 'keyword' => 'sample keyword 34', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 99, 'keyword' => 'sample keyword 35', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 100, 'keyword' => 'sample keyword 36', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 97, 'keyword' => 'sample keyword 37', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 96, 'keyword' => 'sample keyword 38', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 95, 'keyword' => 'sample keyword 39', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 94, 'keyword' => 'sample keyword 40', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 93, 'keyword' => 'sample keyword 41', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 92, 'keyword' => 'sample keyword 42', 'type' => 'NATURAL', 'longname' => 'UK' ), array( 'keywordid' => 91, 'keyword' => 'sample keyword 43', 'type' => 'NATURAL', 'longname' => 'UK' ) ); echo '<h1>Unordered Array</h1><pre>'; print_r($data); echo '</pre>'; echo '<h1>Order Array</h1>'; echo '<pre>'; $order = array(100, 91, 95); print_r($order); echo '</pre>'; $order = array_flip($order); usort($data, function($a, $b) use($order) { if (!isset($order[$a['keywordid']])) { return -1; } if (!isset($order[$b['keywordid']])) { return 1; } if ($k1 == $k2) { return 0; } return ($order[$a['keywordid']] > $order[$b['keywordid']]) ? 1 : -1; }); echo '<h1>Ordered Array</h1><pre>'; print_r($data); echo '</pre>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZkJcR
function name:  (null)
number of ops:  29
compiled vars:  !0 = $data, !1 = $order
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   66     1        ECHO                                                     '%3Ch1%3EUnordered+Array%3C%2Fh1%3E%3Cpre%3E'
   67     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   68     5        ECHO                                                     '%3C%2Fpre%3E'
   70     6        ECHO                                                     '%3Ch1%3EOrder+Array%3C%2Fh1%3E'
   72     7        ECHO                                                     '%3Cpre%3E'
   73     8        ASSIGN                                                   !1, <array>
   74     9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   75    12        ECHO                                                     '%3C%2Fpre%3E'
   77    13        INIT_FCALL                                               'array_flip'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $6      
         16        ASSIGN                                                   !1, $6
   78    17        INIT_FCALL                                               'usort'
         18        SEND_REF                                                 !0
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FZkJcR%3A78%240'
         20        BIND_LEXICAL                                             ~8, !1
   89    21        SEND_VAL                                                 ~8
         22        DO_ICALL                                                 
   91    23        ECHO                                                     '%3Ch1%3EOrdered+Array%3C%2Fh1%3E%3Cpre%3E'
   92    24        INIT_FCALL                                               'print_r'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                                 
   93    27        ECHO                                                     '%3C%2Fpre%3E'
         28      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FZkJcR%3A78%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZkJcR
function name:  {closure}
number of ops:  27
compiled vars:  !0 = $a, !1 = $b, !2 = $order, !3 = $k1, !4 = $k2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   79     3        FETCH_DIM_R                                      ~5      !0, 'keywordid'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !2, ~5
          5        BOOL_NOT                                         ~7      ~6
          6      > JMPZ                                                     ~7, ->8
   80     7    > > RETURN                                                   -1
   82     8    >   FETCH_DIM_R                                      ~8      !1, 'keywordid'
          9        ISSET_ISEMPTY_DIM_OBJ                         0  ~9      !2, ~8
         10        BOOL_NOT                                         ~10     ~9
         11      > JMPZ                                                     ~10, ->13
   83    12    > > RETURN                                                   1
   85    13    >   IS_EQUAL                                                 !3, !4
         14      > JMPZ                                                     ~11, ->16
   86    15    > > RETURN                                                   0
   88    16    >   FETCH_DIM_R                                      ~12     !0, 'keywordid'
         17        FETCH_DIM_R                                      ~13     !2, ~12
         18        FETCH_DIM_R                                      ~14     !1, 'keywordid'
         19        FETCH_DIM_R                                      ~15     !2, ~14
         20        IS_SMALLER                                               ~15, ~13
         21      > JMPZ                                                     ~16, ->24
         22    >   QM_ASSIGN                                        ~17     1
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~17     -1
         25    > > RETURN                                                   ~17
   89    26*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FZkJcR%3A78%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.81 ms | 1400 KiB | 19 Q