3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Re-order the characters from $T using the order of characters in $O. * * @param string $T the string to re-order * @param string $O the string that specifies the desired order * @return string the re-ordered $T */ function reorder($T, $O) { // Convert $T and $O to arrays of characters $t = str_split($T); $o = str_split($O); // Compute the index of each character from $T in $O // Use -1 for characters that do not appear in $O $m = array_map(function($x) use ($o) { $p = array_search($x, $o); return ($p === FALSE) ? -1 : $p; }, $t ); // Sort $m and $t simultaneously; $t will follow the changes applied to $m array_multisort($m, $t); // Join the sorted characters of $T back and return as string return implode('', $t); } $order = 'eloh'; echo('hello => '.reorder('hello', $order)."\n"); echo('help => '.reorder('help', $order)."\n");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vnoC1
function name:  (null)
number of ops:  16
compiled vars:  !0 = $order
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, 'eloh'
   32     1        INIT_FCALL                                               'reorder'
          2        SEND_VAL                                                 'hello'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        CONCAT                                           ~3      'hello+%3D%3E+', $2
          6        CONCAT                                           ~4      ~3, '%0A'
          7        ECHO                                                     ~4
   33     8        INIT_FCALL                                               'reorder'
          9        SEND_VAL                                                 'help'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $5      
         12        CONCAT                                           ~6      'help++%3D%3E+', $5
         13        CONCAT                                           ~7      ~6, '%0A'
         14        ECHO                                                     ~7
         15      > RETURN                                                   1

Function reorder:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vnoC1
function name:  reorder
number of ops:  27
compiled vars:  !0 = $T, !1 = $O, !2 = $t, !3 = $o, !4 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'str_split'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !2, $5
   13     6        INIT_FCALL                                               'str_split'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !3, $7
   17    10        INIT_FCALL                                               'array_map'
         11        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FvnoC1%3A17%240'
         12        BIND_LEXICAL                                             ~9, !3
   20    13        SEND_VAL                                                 ~9
   21    14        SEND_VAR                                                 !2
         15        DO_ICALL                                         $10     
   17    16        ASSIGN                                                   !4, $10
   25    17        INIT_FCALL                                               'array_multisort'
         18        SEND_REF                                                 !4
         19        SEND_REF                                                 !2
         20        DO_ICALL                                                 
   28    21        INIT_FCALL                                               'implode'
         22        SEND_VAL                                                 ''
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $13     
         25      > RETURN                                                   $13
   29    26*     > RETURN                                                   null

End of function reorder

Function %00%7Bclosure%7D%2Fin%2FvnoC1%3A17%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vnoC1
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $x, !1 = $o, !2 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   18     2        INIT_FCALL                                               'array_search'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !2, $3
   19     7        TYPE_CHECK                                    4          !2
          8      > JMPZ                                                     ~5, ->11
          9    >   QM_ASSIGN                                        ~6      -1
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~6      !2
         12    > > RETURN                                                   ~6
   20    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FvnoC1%3A17%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.84 ms | 1403 KiB | 25 Q