<?php
function reverse_vowels($word) {
preg_match_all('/[ayeiou]/i', $word, $matches);
$vowels = $matches[0];
foreach(str_split($word) as $i=>$c) {
if (in_array($c, $matches[0])) {
$word[$i] = array_pop($vowels);
}
}
return $word;
}
echo reverse_vowels('kapez');
function reverse_vowels($word) {
preg_match_all('/[ayeiou]/i', $word, $matches);
$vowels = $matches[0];
foreach(str_split($word) as $i=>$c) {
if (in_array($word[$i], $vowels)) {
$word[$i] = array_pop($vowels);
}
}
return $word;
}