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'));
Output for git.master, git.master_jit, rfc.property-hooks
string(4) "taxi"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
58.31 ms | 401 KiB | 8 Q