Computer

PHP/Oracle Development


Syllabus
Schedule
Reading
Discussion
Project
Test
Resource
Tip

Review Questions: Week 3
(Control St
rutures)

  1. What is the output from the following PHP code?

    <?php
    $string1 = "cake";
    $string2 = "foo";

    if($string1==$string2)
    {
    print "\$string1=".$string1."<br>";
    print "\$string2=".$string2."<br>";
    echo "cake is not a lie. <br>";
    }
    ?>


    I tested every code when I made those questions. Thus, it is fair to ask you to test them to make sure your answer is correct.


  2. What is the output from the following PHP code?

    <?php
    $string1 = "cake";
    $string2 = "foo";

    if($string1!=$string2)
    {
    print "\$string1=".$string1."<br>";
    print "\$string2=".$string2."<br>";
    echo "cake is not a lie. <br>";
    }
    ?>



  3. What is the output from the following PHP code?

    <?php
    $string1 = "cake";
    $string2 = "foo";

    if($string1=$string2)
    {
    print "\$string1=".$string1."<br>";
    print "\$string2=".$string2."<br>";
    echo "cake is a lie. <br>";
    }
    ?>





  4. What is the output from the following PHP code?

    <?php
    $string1 = "cake";
    $string2 = "foo";

    if(!$string1==$string2)
    {
    print "\$string1=".$string1."<br>";
    print "\$string2=".$string2."<br>";
    echo "cake is a lie. <br>";
    }
    ?>




  5. What is the output from the following PHP code? (This example shows that string can be used in "switch" control as well as numerals.)

    <?php
    $i="bar";

    switch ($i)
    {

    case "apple":
    echo "i is apple &nbsp";
    break;

    case "bar":
    echo "i is bar &nbsp";
    break;

    case "cake":
    echo "i is cake &nbsp";
    break;

    default:
    echo "i is nothing&nbsp";
    break;

    }
    ?>


    The "&nbsp" just provides a space.




  6. What is the output from the following PHP code?

    <?php
    $i="bar";

    switch ($i)

    {
    case "apple":
    echo "i is apple &nbsp";
    break;

    case "bar":
    echo "i is bar &nbsp";
    break

    case "cake":
    echo "i is cake &nbsp";
    break;

    default:
    echo "i is nothing &nbsp";
    break;
    }

    ?>



  7. What is the output from the following PHP code?

    <?php
    $i="bar";

    switch ($i)

    {
    case "apple":
    echo "i is apple<br>";
    break;

    case "bar":
    echo "i is bar<br>";

    case "cake":
    echo "i is cake<br>";
    break;

    default:
    echo "i is nothing<br>";
    break;
    }

    ?>



  8. What is the output from the following PHP code?

    <?php

    $myVariable = 2;
    do {
    echo $myVariable;
    } while ($myVariable > 3);

    ?>



  9. What is the output from the following PHP code?

    <?php

    $myVariable = 2;
    while ($myVariable > 3)
    {
    echo $myVariable;
    }

    ?>




  10. What is the output from the following PHP code?
    <?php
    $i = 1;
    while ($i <= 10) {
    echo $i++;
    }


  11. What is the output from the following PHP code?
    <?php
    for ($i = 1; $i <= 5; $i++) {
    print $i;
    }
    ?>


  12. What is the output from the following PHP code?
    <?php
    for ($i = 1; $i <= 5; ++$i) {
    print $i;
    }
    ?>



  13. What is the output from the following PHP code?
    <?php
    for ($i = 5; $i >= 1; $i--) {
    print $i;
    }
    ?>




  14. What is the output from the following PHP code?

    <?php
    $MyArray = array("one", "two", "three");

    foreach ($MyArray as $value) {
    echo "Value: $value,;
    }
    ?>




  15. What is the output from the following PHP code?

    <?php

    $myVariable = 4;
    while ($myVariable > 3)
    {
    echo $myVariable;
    }

    ?>