Skip to content

Instantly share code, notes, and snippets.

@naagaraa
Created April 26, 2022 22:06
Show Gist options
  • Save naagaraa/0ccd5b5cdca6ec85412d38ae92f3808c to your computer and use it in GitHub Desktop.
Save naagaraa/0ccd5b5cdca6ec85412d38ae92f3808c to your computer and use it in GitHub Desktop.
test 1
<?php
function vocal($string = "")
{
$string = str_split(str_replace(" ", "", strtolower($string)));
$vocal = "aiueo";
$result = [];
foreach ($string as $key => $value) {
if (str_contains($vocal, $value)) {
array_push($result, $value);
}
}
sort($result);
return implode("", $result);
}
/**
* remove vowel char return sort character
*
* @param array $string
* @return void
*/
function konsonan($string = "")
{
$string = str_split(str_replace(" ", "", strtolower($string)));
$vocal = "aiueo";
$result = [];
foreach ($string as $key => $value) {
if (!str_contains($vocal, $value)) {
array_push($result, $value);
}
}
ksort($result);
return implode("", $result);
}
function main($string = "")
{
echo vocal($string) . "<br>";
echo konsonan($string) . "<br>";
}
main("sample case");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment