Skip to content

Instantly share code, notes, and snippets.

@syofyanzuhad
Created September 29, 2022 13:18
Show Gist options
  • Save syofyanzuhad/e6dadc06c6ab569f400a3d57e9cae537 to your computer and use it in GitHub Desktop.
Save syofyanzuhad/e6dadc06c6ab569f400a3d57e9cae537 to your computer and use it in GitHub Desktop.
<?php
$string = "Indonesia";
function vowelCheck($string)
{
$lower = strtolower($string);
$split = str_split($lower);
$vowel = [];
foreach ($split as $value) {
if (preg_match('/^[aeiou]/i', $value)) {
array_push($vowel, $value);
}
}
$result = array_unique($vowel);
echo "\"$string\" = " . count($result) . " huruf vokal, yaitu " . join($result, ", ");
echo "\n";
}
vowelCheck($string);
// "Indonesia" = 4 huruf vokal, yaitu i, o, e, a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment