3v4l.org

run code in 300+ PHP versions simultaneously
<?php $order = array( 3452342, 5867867, 7867867, 1231233 ); $array = array( array("id" => 7867867, "title" => "Must Be #3"), array("id" => 3452342, "title" => "Must Be #1"), array("id" => 1231233, "title" => "Must Be #4"), array("id" => 5867867, "title" => "Must Be #2"), array("id" => 1111111, "title" => "Dont Care #1"), array("id" => 2222222, "title" => "Dont Care #2"), array("id" => 3333333, "title" => "Dont Care #3"), array("id" => 4444444, "title" => "Dont Care #4") ); function custom_compare($a, $b){ global $order; $a = array_search($a["id"], $order); $b = array_search($b["id"], $order); if($a === false && $b === false) { // both items are dont cares return 0; // a == b } else if ($a === false) { // $a is a dont care item return 1; // $a > $b } else if ($b === false) { // $b is a dont care item return -1; // $a < $b } else { return $a - $b; } } shuffle($array); // for testing var_dump($array); // before usort($array, "custom_compare"); var_dump($array); // after ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XApID
function name:  (null)
number of ops:  16
compiled vars:  !0 = $order, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   36     2        INIT_FCALL                                               'shuffle'
          3        SEND_REF                                                 !1
          4        DO_ICALL                                                 
   37     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   38     8        INIT_FCALL                                               'usort'
          9        SEND_REF                                                 !1
         10        SEND_VAL                                                 'custom_compare'
         11        DO_ICALL                                                 
   39    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
   40    15      > RETURN                                                   1

Function custom_compare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/XApID
function name:  custom_compare
number of ops:  33
compiled vars:  !0 = $a, !1 = $b, !2 = $order
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        BIND_GLOBAL                                              !2, 'order'
   21     3        INIT_FCALL                                               'array_search'
          4        FETCH_DIM_R                                      ~3      !0, 'id'
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !0, $4
   22     9        INIT_FCALL                                               'array_search'
         10        FETCH_DIM_R                                      ~6      !1, 'id'
         11        SEND_VAL                                                 ~6
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !1, $7
   23    15        TYPE_CHECK                                    4  ~9      !0
         16      > JMPZ_EX                                          ~9      ~9, ->19
         17    >   TYPE_CHECK                                    4  ~10     !1
         18        BOOL                                             ~9      ~10
         19    > > JMPZ                                                     ~9, ->22
   24    20    > > RETURN                                                   0
         21*       JMP                                                      ->32
   26    22    >   TYPE_CHECK                                    4          !0
         23      > JMPZ                                                     ~11, ->26
   27    24    > > RETURN                                                   1
         25*       JMP                                                      ->32
   29    26    >   TYPE_CHECK                                    4          !1
         27      > JMPZ                                                     ~12, ->30
   30    28    > > RETURN                                                   -1
         29*       JMP                                                      ->32
   33    30    >   SUB                                              ~13     !0, !1
         31      > RETURN                                                   ~13
   35    32*     > RETURN                                                   null

End of function custom_compare

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.06 ms | 1392 KiB | 21 Q