Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function is_vowel($c){
return preg_match('/[ayeiou]/i', $c);
};
function reverse_vowels($word) {
$vowels = [];
foreach(str_split($word) as $c) {
if (is_vowel($c)) {
$vowels[] = $c;
}
}
foreach(str_split($word) as $i=>$c) {
if (is_vowel($word[$i])) $word[$i] = array_pop($vowels);
}
return $word;
}
echo reverse_vowels('environment');