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