3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isAnagram( $phrase1, $phrase2 ) { $phrase1 = strtolower(preg_replace("/[^a-zA-Z]/", "", $phrase1)); $phrase2 = strtolower(preg_replace("/[^a-zA-Z]/", "", $phrase2)); // todo: fix splitting $a1 = str_split($phrase1); $a2 = str_split($phrase2); sort($a1); sort($a2); $phrase1 = join("",$a1); $phrase2 = join("",$a2); return ( $phrase1 === $phrase2 ); } echo "Test1 = " . (isAnagram( "", "" ) ? "Is anagram" : "Is not") . "\n"; echo "Test2 = " . (isAnagram( "Dormitory", "Dirty room" ) ? "Is anagram" : "Is not") . "\n"; echo "Test3 = " . (isAnagram( "A decimal point", "I'm a dot in place" ) ? "Is anagram" : "Is not") . "\n"; echo "Test4 = " . (isAnagram( "A decimal point no?", "I'm a dot in place" ) ? "Is anagram" : "Is not") . "\n"; echo "Test5 = " . (isAnagram( "A decimal point", "I'm a dot in place yes?" ) ? "Is anagram" : "Is not") . "\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
Branch analysis from position: 51
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
Branch analysis from position: 40
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
Branch analysis from position: 29
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
Branch analysis from position: 18
filename:       /in/AjE1M
function name:  (null)
number of ops:  56
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'isanagram'
          1        SEND_VAL                                                 ''
          2        SEND_VAL                                                 ''
          3        DO_FCALL                                      0  $0      
          4      > JMPZ                                                     $0, ->7
          5    >   QM_ASSIGN                                        ~1      'Is+anagram'
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~1      'Is+not'
          8    >   CONCAT                                           ~2      'Test1+%3D+', ~1
          9        CONCAT                                           ~3      ~2, '%0A'
         10        ECHO                                                     ~3
   23    11        INIT_FCALL                                               'isanagram'
         12        SEND_VAL                                                 'Dormitory'
         13        SEND_VAL                                                 'Dirty+room'
         14        DO_FCALL                                      0  $4      
         15      > JMPZ                                                     $4, ->18
         16    >   QM_ASSIGN                                        ~5      'Is+anagram'
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~5      'Is+not'
         19    >   CONCAT                                           ~6      'Test2+%3D+', ~5
         20        CONCAT                                           ~7      ~6, '%0A'
         21        ECHO                                                     ~7
   24    22        INIT_FCALL                                               'isanagram'
         23        SEND_VAL                                                 'A+decimal+point'
         24        SEND_VAL                                                 'I%27m+a+dot+in+place'
         25        DO_FCALL                                      0  $8      
         26      > JMPZ                                                     $8, ->29
         27    >   QM_ASSIGN                                        ~9      'Is+anagram'
         28      > JMP                                                      ->30
         29    >   QM_ASSIGN                                        ~9      'Is+not'
         30    >   CONCAT                                           ~10     'Test3+%3D+', ~9
         31        CONCAT                                           ~11     ~10, '%0A'
         32        ECHO                                                     ~11
   25    33        INIT_FCALL                                               'isanagram'
         34        SEND_VAL                                                 'A+decimal+point+no%3F'
         35        SEND_VAL                                                 'I%27m+a+dot+in+place'
         36        DO_FCALL                                      0  $12     
         37      > JMPZ                                                     $12, ->40
         38    >   QM_ASSIGN                                        ~13     'Is+anagram'
         39      > JMP                                                      ->41
         40    >   QM_ASSIGN                                        ~13     'Is+not'
         41    >   CONCAT                                           ~14     'Test4+%3D+', ~13
         42        CONCAT                                           ~15     ~14, '%0A'
         43        ECHO                                                     ~15
   26    44        INIT_FCALL                                               'isanagram'
         45        SEND_VAL                                                 'A+decimal+point'
         46        SEND_VAL                                                 'I%27m+a+dot+in+place+yes%3F'
         47        DO_FCALL                                      0  $16     
         48      > JMPZ                                                     $16, ->51
         49    >   QM_ASSIGN                                        ~17     'Is+anagram'
         50      > JMP                                                      ->52
         51    >   QM_ASSIGN                                        ~17     'Is+not'
         52    >   CONCAT                                           ~18     'Test5+%3D+', ~17
         53        CONCAT                                           ~19     ~18, '%0A'
         54        ECHO                                                     ~19
         55      > RETURN                                                   1

Function isanagram:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AjE1M
function name:  isAnagram
number of ops:  47
compiled vars:  !0 = $phrase1, !1 = $phrase2, !2 = $a1, !3 = $a2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'strtolower'
          3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAL                                                 '%2F%5B%5Ea-zA-Z%5D%2F'
          5        SEND_VAL                                                 ''
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !0, $5
    6    11        INIT_FCALL                                               'strtolower'
         12        INIT_FCALL                                               'preg_replace'
         13        SEND_VAL                                                 '%2F%5B%5Ea-zA-Z%5D%2F'
         14        SEND_VAL                                                 ''
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $7      
         17        SEND_VAR                                                 $7
         18        DO_ICALL                                         $8      
         19        ASSIGN                                                   !1, $8
    9    20        INIT_FCALL                                               'str_split'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $10     
         23        ASSIGN                                                   !2, $10
   10    24        INIT_FCALL                                               'str_split'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $12     
         27        ASSIGN                                                   !3, $12
   12    28        INIT_FCALL                                               'sort'
         29        SEND_REF                                                 !2
         30        DO_ICALL                                                 
   13    31        INIT_FCALL                                               'sort'
         32        SEND_REF                                                 !3
         33        DO_ICALL                                                 
   15    34        INIT_FCALL                                               'join'
         35        SEND_VAL                                                 ''
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $16     
         38        ASSIGN                                                   !0, $16
   16    39        INIT_FCALL                                               'join'
         40        SEND_VAL                                                 ''
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                         $18     
         43        ASSIGN                                                   !1, $18
   19    44        IS_IDENTICAL                                     ~20     !0, !1
         45      > RETURN                                                   ~20
   20    46*     > RETURN                                                   null

End of function isanagram

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.24 ms | 952 KiB | 29 Q