Computer

PHP/Oracle Development


Syllabus
Schedule
Reading
Discussion
Project
Test
Resource
Tip

Review Questions: Week 4
(
Arrays)

  1. What is the content of $student[1] from the following PHP code?

    <?php
    // Define the array.
    $student = array("1","London","Donovan","3", "Yes","A");

    print "The student's id is ".$student[0]."</br>";
    print "The student's first name is ".$student[1]."</br>";
    print "The student's last name is ".$student[2]."</br>";
    print "The student spends ".$student[3]. " hours for this great PHP class.</br>";
    print "Does the student has a sense of humor? ".$student[4]."</br>";
    print "The student's potential grade is ".$student[5]."</br>";

    ?>




  2. What is the content of $student[3] from the following PHP code?

    <?php
    // Define the array.
    $student = array("1","London","Donovan","3", "Yes","A");

    print "The student's id is ".$student[0]."</br>";
    print "The student's first name is ".$student[1]."</br>";
    print "The student's last name is ".$student[2]."</br>";
    print "The student spends ".$student[3]. " hours for this great PHP class.</br>";
    print "Does the student has a sense of humor? ".$student[4]."</br>";
    print "The student's potential grade is ".$student[5]."</br>";

    ?>



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

    <?php
    // Define the array.
    $student = array("1","London","Donovan","3", "Yes","A");
    $output="";

    // Read and add array keys and values to a string.
    foreach ($student as $hashName => $hashValue)
    $output .= $hashValue."&nbsp";

    // Print the contents only.
    print "This row shows the content of the array only. </br> ";
    print $output;

    ?>





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

    <?php
    $student = array("1","London","Donovan","3", "Yes","A");
    print count($student);
    ?>




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

    <?php
    $student =array("1","London","Donovan","3", "Yes","A");

    //$student =3;

    if (is_array($student))

    {
    $output="";
    foreach ($student as $hashName => $hashValue)
    $output .= $hashValue."&nbsp";
    print $output;
    }
    else
    {
    print "The \$student variable is not an array.";
    }

    ?>








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

    <?php
    //$student =array("1","London","Donovan","3", "Yes","A");

    $student =3;

    if (is_array($student))

    {
    $output="";
    foreach ($student as $hashName => $hashValue)
    $output .= $hashValue."&nbsp";
    print $output;
    }
    else
    {
    print "The \$student variable is not an array.";
    }

    ?>