Exemple #1
0
    $singleChar = array_shift($arrayChar);
    while (!isVowel($singleChar)) {
        $arrayChar[] = $singleChar;
        $singleChar = array_shift($arrayChar);
    }
    array_push($arrayChar, "ay");
    return ucfirst(implode($arrayChar));
}
$outputArray = array("Banana", "Cranberry", "Pistachio", "Marshmallow", "Almond", "Mozzarella", "Gouda", "Avocado");
/*
 * Create an array from the following strings:
 *   Banana, Cranberry, Pistachio, Marshmallow, Almond, Mozzarella, Gouda, Avocado
 * Iterate through the array and print a table that has the index of the element in the first column,
 * the original word in the second column, and the Pig Latin translation in the third column.
 */
?>

    <!-- print your results here! -->
    <table>
    <?php 
foreach ($outputArray as $key => $a) {
    echo "<tr><td>" . $key . "</td><td>" . $a . "</td><td>" . make_pig_latin($a) . "</td></tr>";
}
?>
    </table>

</body>

</html>

    for ($x = 1; $x < count($letter); $x++) {
        for ($y = 0; $y < count($vowel); $y++) {
            if ($letter[0] == $vowel[$y]) {
                $piglatin .= $string . "yay";
                return strtolower($piglatin);
            } else {
                if ($letter[$x] == $vowel[$y]) {
                    $piglatin .= substr($string, $x) . substr($string, 0, $x) . "ay";
                    return strtolower($piglatin);
                }
            }
        }
    }
}
/*
 * Create an array from the following strings:
 *   Banana, Cranberry, Pistachio, Marshmallow, Almond, Mozzarella, Gouda, Avocado
 * Iterate through the array and print a table that has the index of the element in the first column,
 * the original word in the second column, and the Pig Latin translation in the third column.
 */
$food = array("Banana", "Cranberry", "Pistachio", "Marshmallow", "Almond", "Mozzarella", "Gouda", "Avocado");
$arr_length = count($food);
/* printing results here! */
for ($i = 0; $i < $arr_length; $i++) {
    echo "<tr><td>" . ($i + 1) . "</td><td>" . $food[$i] . "</td><td>" . make_pig_latin($food[$i]) . "</td></tr>";
}
?>
</table>
</body>
</html>