3v4l.org

run code in 300+ PHP versions simultaneously
<?php function high($input) { // Initialize: Convert the string to lowercase, and generate an array of the alphabet $input = strtolower($input); $alphabet = range('a', 'z'); $values = array_flip($alphabet); // Split the words into an array, and declare initial scores $words = explode(" ", $input); $highestScore = null; $highestIndex = null; // Iterate over each word foreach($words as $k=>$w) { // Calculate the score of the current word // The score is the position of the flipped alphabet array, or 0 if its not in the lsit $score = array_sum(array_map(function($v) use ($values) { return $values[$v] ?? 0; }, str_split($w))); // If the current score is higher than the previous highest, overwrite it if ($highestScore < $score) { $highestScore = $score; $highestIndex = $k; } } // Return the word at the index where the score was the highest // If there were no scores (if $input is empty), return a default message return $words[$highestIndex] ?? 'N/A - No words found'; } var_dump(high('man i need a taxi up to ubud'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4ESFG
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'high'
          2        SEND_VAL                                                 'man+i+need+a+taxi+up+to+ubud'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function high:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 42
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 42
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 41
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/4ESFG
function name:  high
number of ops:  48
compiled vars:  !0 = $input, !1 = $alphabet, !2 = $values, !3 = $words, !4 = $highestScore, !5 = $highestIndex, !6 = $w, !7 = $k, !8 = $score
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $9      
          4        ASSIGN                                                   !0, $9
    6     5        INIT_FCALL                                               'range'
          6        SEND_VAL                                                 'a'
          7        SEND_VAL                                                 'z'
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !1, $11
    7    10        INIT_FCALL                                               'array_flip'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $13     
         13        ASSIGN                                                   !2, $13
   10    14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '+'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $15     
         18        ASSIGN                                                   !3, $15
   11    19        ASSIGN                                                   !4, null
   12    20        ASSIGN                                                   !5, null
   15    21      > FE_RESET_R                                       $19     !3, ->42
         22    > > FE_FETCH_R                                       ~20     $19, !6, ->42
         23    >   ASSIGN                                                   !7, ~20
   18    24        INIT_FCALL                                               'array_sum'
         25        INIT_FCALL                                               'array_map'
         26        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F4ESFG%3A18%240'
         27        BIND_LEXICAL                                             ~22, !2
   20    28        SEND_VAL                                                 ~22
         29        INIT_FCALL                                               'str_split'
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                         $23     
         32        SEND_VAR                                                 $23
         33        DO_ICALL                                         $24     
         34        SEND_VAR                                                 $24
         35        DO_ICALL                                         $25     
   18    36        ASSIGN                                                   !8, $25
   23    37        IS_SMALLER                                               !4, !8
         38      > JMPZ                                                     ~27, ->41
   24    39    >   ASSIGN                                                   !4, !8
   25    40        ASSIGN                                                   !5, !7
   15    41    > > JMP                                                      ->22
         42    >   FE_FREE                                                  $19
   31    43        FETCH_DIM_IS                                     ~30     !3, !5
         44        COALESCE                                         ~31     ~30
         45        QM_ASSIGN                                        ~31     'N%2FA+-+No+words+found'
         46      > RETURN                                                   ~31
   32    47*     > RETURN                                                   null

End of function high

Function %00%7Bclosure%7D%2Fin%2F4ESFG%3A18%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4ESFG
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $v, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   19     2        FETCH_DIM_IS                                     ~2      !1, !0
          3        COALESCE                                         ~3      ~2
          4        QM_ASSIGN                                        ~3      0
          5      > RETURN                                                   ~3
   20     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F4ESFG%3A18%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.02 ms | 1403 KiB | 30 Q