Skip to content

Instantly share code, notes, and snippets.

@magmastonealex
Created October 18, 2013 01:29
Show Gist options
  • Save magmastonealex/7035095 to your computer and use it in GitHub Desktop.
Save magmastonealex/7035095 to your computer and use it in GitHub Desktop.
Declare string to check
String with All of the vowels
String with All of the consonants
Make variable to count vowels
Make variable to count consonants
For length of string
Set achar to the current character of the strings
For length of vowels
If the current vowel equals the current character
Increase vowel count
For length of consonants
If the current consonants equals the current character
Increase consonants count
Print them out
<?php
$strcheck="Testing"; //Declare string to check
$vow="aeiouyAEIOUY"; // All of the vowels
$alpha="bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ"; // All of the consonants
$vowels=0; //Make variable to count vowels
$const=0; //Make variable to count consonants
for( $i=0; $i < strlen($strcheck);$i++){ //For length of string
$achar = $strcheck[$i]; //Set achar to the current character of the strings
for($x=0; $x<strlen($vow); $x++){ //For length of vowels
if($vow[$x] == $achar){ //If the current vowel equals the current character
$vowels++; //Increase vowel count
}
}
for($x=0; $x<strlen($alpha); $x++){ //For length of consonants
if($alpha[$x] == $achar) //If the current consonants equals the current character
$const++; //Increase consonants count
}
}
}
echo $vowels." vowels<br />"; //Print them out
echo $const." Consonants<br />";
?>
<?php
$m = 2;
$nums = "13"; // missing is 3
$missing = 0;
for($i = 1; $i<$m+2; $i++){
$check = $i;
// echo "Checking: $i<br>";
$good=0;
for($x=0;$x<strlen($nums); $x++){
if(intval($nums[$x]) == $i){
$good=1;
// echo "Good: $i<br>";
}
}
if($good==0){
$missing=$i;
break
}
}
echo $missing;
?>
<?php
$string="ABCAB";
$missing="";
for($i = 0; $i<strlen($string); $i++){
$check = $string[$i];
// echo "Checking: $check<br>";
$good=1;
for($x=0;$x<strlen($string); $x++){
if($check == $string[$x] && $x != $i){
$good=0;
// echo "Good: $x<br>";
}
}
if($good==1){
$missing=$string[$i];
break;
}
}
echo $missing;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment