- substr: documentation ( source)
- print_r: documentation ( source)
- in_array: documentation ( source)
- str_split: documentation ( source)
<?php
function getCount($str) {
$vowelsCount = 0;
$vowels = array('a', 'e', 'i', 'o', 'u');
$letters = str_split($str);
print_r($letters);
foreach ($letters as $letter) {
if (in_array($letter, $vowels)) {
$vowelsCount++;
}
}
return $vowelsCount;
}
echo getCount('heyo');
function getMiddle($text) {
$length = strlen($text);
if ($length%2 == 0) {
echo $length/2;
return substr($text, $length/2 - 1, 2);
}
else {
return substr($text, $length/2, 1);
}
}
//echo getMiddle('test');