3v4l.org

run code in 300+ PHP versions simultaneously
<?php $order = array( 85, 35, 58, 68 ); $array = array( array("id" => 58, "title" => "Must Be #3"), array("id" => 85, "title" => "Must Be #1"), array("id" => 68, "title" => "Must Be #4"), array("id" => 35, "title" => "Must Be #2"), array("id" => 69, "title" => "Dont Care #1"), array("id" => 77, "title" => "Dont Care #2"), array("id" => 79, "title" => "Dont Care #3"), array("id" => 80, "title" => "Dont Care #4") ); function custom_compare($a, $b){ global $order; var_dump($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; } } 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/TN262
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>
   37     2        INIT_FCALL                                               'usort'
          3        SEND_REF                                                 !1
          4        SEND_VAL                                                 'custom_compare'
          5        DO_ICALL                                                 
   38     6      > FE_RESET_R                                       $6      !1, ->14
          7    > > FE_FETCH_R                                               $6, !2, ->14
   39     8    >   FETCH_DIM_R                                      ~7      !2, 'id'
          9        ECHO                                                     ~7
   40    10        FETCH_DIM_R                                      ~8      !2, 'title'
         11        ECHO                                                     ~8
   41    12        ECHO                                                     '%0D%0A'
   38    13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $6
   44    15      > RETURN                                                   1

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

End of function custom_compare

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.15 ms | 1405 KiB | 19 Q