Пример #1
0
}
/**
 * Check if the letters from the fruitmachine are equal. 
 * If the letters are equal --> Output Jackpot!
 * @param type $letters the letters from the fruitmachine
 */
function areValuesEqual($letters)
{
    if (count(array_unique($letters)) == 1) {
        echo "<p class='jackpot'>Jackpot!!</p>";
    }
}
echo "<div class=letters>";
# Generate and show 3 letters to the screen
for ($i = 1; $i <= 3; $i++) {
    $randomLetter = randomLetter();
    echo "<div class='letter'>" . $randomLetter . "</div>";
    array_push($generatedLetters, $randomLetter);
}
# After the letters have been generated, check if they are all equal
areValuesEqual($generatedLetters);
echo "</div>";
# Template data
$the_title = "Week 6: Fruitmachine";
$the_content = ob_get_clean();
$show_source = array("15_fruitmachine.php" => __FILE__);
include "sidebar_array.php";
$sidebar_array = sidebar_array();
$sidebar_header = "Opdrachten PHP";
$assignment_description = "\n    <p>Schrijf een functie die willekeurige reeksen van 3 letters (A,B,C) \nteruggeeft. Bijvoorbeeld A C B, B B A, C A C. Gebruik hiervoor de PHP \nfunctie <em>mt_rand()</em>. Als de letters driemaal hetzelfde zijn, dan wordt de \nboodschap 'Jackpot' getoond. \nToon de letter reeksen in aparte div elementen en geef ze vorm met CSS. </p>";
?>
Пример #2
0
function randomWord($length, $capitalize = false, $vowelSense, $nums, $specialChars)
{
    if ($specialChars) {
        $consonants = implode(range(chr(33), chr(255)));
    } else {
        $consonants = "bcdfghjlmnpqrst" . ($nums ? "1234567890" : "");
    }
    $vowels = "aeiouy";
    $wordString = "";
    for ($i = 0; $i < $length; $i++) {
        if ($vowelSense) {
            if (strpos($vowels, !isset($lastRandomChar) ? "a" : $lastRandomChar) === false) {
                $randomChar = randomLetter($vowels);
            } else {
                $randomChar = randomLetter($consonants);
            }
            $lastRandomChar = $randomChar;
        } else {
            $randomChar = randomLetter($vowels . $consonants);
        }
        $wordString .= $randomChar;
    }
    if ($capitalize) {
        return ucfirst($wordString);
    } else {
        return $wordString;
    }
}