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); echo $a; echo "\r\n"; $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; } } usort($array, "custom_compare"); foreach($array as $item): echo $item["id"]; echo $item["title"]; echo "\r\n"; endforeach; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/dF6bd
function name:  (null)
number of ops:  16
compiled vars:  !0 = $order, !1 = $array, !2 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   38     2        INIT_FCALL                                               'usort'
          3        SEND_REF                                                 !1
          4        SEND_VAL                                                 'custom_compare'
          5        DO_ICALL                                                 
   39     6      > FE_RESET_R                                       $6      !1, ->14
          7    > > FE_FETCH_R                                               $6, !2, ->14
   40     8    >   FETCH_DIM_R                                      ~7      !2, 'id'
          9        ECHO                                                     ~7
   41    10        FETCH_DIM_R                                      ~8      !2, 'title'
         11        ECHO                                                     ~8
   42    12        ECHO                                                     '%0D%0A'
   39    13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $6
   45    15      > RETURN                                                   1

Function custom_compare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/dF6bd
function name:  custom_compare
number of ops:  35
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        ECHO                                                     !0
   23    10        ECHO                                                     '%0D%0A'
   24    11        INIT_FCALL                                               'array_search'
         12        FETCH_DIM_R                                      ~6      !1, 'id'
         13        SEND_VAL                                                 ~6
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !1, $7
   25    17        TYPE_CHECK                                    4  ~9      !0
         18      > JMPZ_EX                                          ~9      ~9, ->21
         19    >   TYPE_CHECK                                    4  ~10     !1
         20        BOOL                                             ~9      ~10
         21    > > JMPZ                                                     ~9, ->24
   26    22    > > RETURN                                                   0
         23*       JMP                                                      ->34
   28    24    >   TYPE_CHECK                                    4          !0
         25      > JMPZ                                                     ~11, ->28
   29    26    > > RETURN                                                   1
         27*       JMP                                                      ->34
   31    28    >   TYPE_CHECK                                    4          !1
         29      > JMPZ                                                     ~12, ->32
   32    30    > > RETURN                                                   -1
         31*       JMP                                                      ->34
   35    32    >   SUB                                              ~13     !0, !1
         33      > RETURN                                                   ~13
   37    34*     > RETURN                                                   null

End of function custom_compare

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.22 ms | 1405 KiB | 17 Q