コード例 #1
0
                </h1>
                <hr />
                <p>
                    <?php 
/**
 * Function that takes in an array of elements and randomly selects and returns an element of that array.
 * 
 * @param array $arrayParam
 * @return element
 */
function randomElement($arrayParam)
{
    $ranElement = array_rand($arrayParam, 1);
    return $arrayParam[$ranElement];
}
echo randomElement(array("Justin", "Danielle", "Rachel", "Will", "Joey", "JP", "Jason", "Aubrey", "Alex"));
?>
                </p>
            </div>
            
            <div>
                <h1>
                    4. Write a function that accepts a string, and checks to 
                    see if it is a palindrome or not (A palindrome is word, 
                    phrase, or sequence that reads the same backward as forward, 
                    e.g., madam or nurses run.). Include PHPDoc.
                </h1>
                <hr />
                <p>
                    <?php 
/** 
コード例 #2
0
function nameServer($nounArray, $adjArray)
{
    $noun = randomElement($nounArray);
    $adj = randomElement($adjArray);
    return "{$adj} {$noun}";
}
コード例 #3
0
function randomNoun()
{
    $nouns = ['Lion', 'Wolf', 'Books', 'Computer', 'Programmer', 'Table', 'Charger', 'Bear', 'Dirk', 'Jeep'];
    return $nouns[randomElement($nouns)];
}