PHP Level 1

10 Questions | Total Attempts: 678

SettingsSettingsSettings
Please wait...
PHP Quizzes & Trivia

This tests your basic understanding of PHP software development, including general programming concepts like recursion, functions, and objects. Passing the test indicates that you recognize and understand basic computer programming, beyond copying data from forms into page layouts, and understand the terminology related with basic computer programming.


Questions and Answers
  • 1. 
    Which of the following doesn't look like PHP code?
    • A. 

      $a = 10;

    • B. 

      If ($this->isComplete()) echo "finished";

    • C. 

      Printf('%d',10);

    • D. 

      Document.writeln(requestObject.parameter("id"))

    • E. 

      Echo $switch ? $switch : '';

  • 2. 
    Which of the following is a function call.
    • A. 

      Fib(5)

    • B. 

      ( $i > LAST_ITEM )

    • C. 

      $n = 100;

    • D. 

      5 + 10

    • E. 

      Function total( $x, $y, $z ) { return $x + $y + $z; }

  • 3. 
    Which of the following is an example of the use of an arithmetic operator?
    • A. 

      While (true) { echo "x"; }

    • B. 

      F(10)

    • C. 

      $a + $b

    • D. 

      $n = array( 1, 3, 9, 27 );

    • E. 

      Print "10 - 5 = 5";

  • 4. 
    Which of the following is not a supported syntax to call a method on an object or a class?
    • A. 

      MyClass::myMethod($x);

    • B. 

      $obj->myMethod($x);

    • C. 

      $obj.myMethod($x);

    • D. 

      $n = new MyClass(10)->myMethod($x);

    • E. 

      $obj->$funcName($parameter);

  • 5. 
    Here is a dense, faulty bit of PHP code that just won't work.  You know, the kind your coworker wrote (lulz).  All of the following reasons, except one, are reasons why the code isn't working.$a = $POST['name'];print 'Hello $a';include('db_layer.inc.php'); // connects to db$db = new db();$db->insert("insert into foobar (name) $a");?>
    • A. 

      The POST variable name is wrong.

    • B. 

      The input is not escaped and quoted before being inserted into the query.

    • C. 

      The "Hello" message was quoted incorrectly, and won't display the arugment.

    • D. 

      The input is not sanitized before printing to the browser.

    • E. 

      An HTML tag is not closed.

  • 6. 
    You have a large array of names, sorted randomly, and you need to extract all the names that start with the letter "M". What kind of magical PHP incantations will appear in your code?
    • A. 

      For(....), if (....) { $a[] = ... }

    • B. 

      Foreach(....) preg_match

    • C. 

      Map( function () = '....' ); substr(); array_push();

    • D. 

      Grep(); keys(); unshift()

    • E. 

      Array(... select from( where(...) );

  • 7. 
    Your client says they want to build a clone of Craigslist or Kijiji.  You think they're nuts, but they convince you they can do it.  Around how many data tables do you think it will take?
    • A. 

      5

    • B. 

      10

    • C. 

      50

    • D. 

      300

    • E. 

      2000

  • 8. 
    You whipped up a little MySQL database backed website, and now the traffic has exploded.  The server is slowing down.  Listed are some ways you can reduce the load.  Which will give you the least gain?
    • A. 

      Analyze your queries, and add indexes to tables to speed them up.

    • B. 

      Add an object cache like APC or Zend.

    • C. 

      Generate a static home page, and for some internal pages.

    • D. 

      Move the database to it's own machine and connect to it via TCP/IP

    • E. 

      Use memcached to store serialized query results, and use it as a result cache.

  • 9. 
    Computer scientists like recursion.  In the real world, especially on multi-user situations like PHP faces, recursion isn't so popular.  There are many reasons why people forego recursion.  Which of the following is usually not a reason.
    • A. 

      Function calls are expensive.

    • B. 

      Function call stack can run out of space.

    • C. 

      Consumes lots of memory.

    • D. 

      Difficult to understand.

    • E. 

      It's easier to use arrays and indices.

  • 10. 
    PHP runs on many platforms, mainly Unixes.  When you run code developed on a Snix machine and move it over to a Windows server, which issue below is not likely to be a problem.
    • A. 

      Case folding causes similarly named files to overwrite another.

    • B. 

      Calling mail() fails.

    • C. 

      Executing code that calls OLE fails.

    • D. 

      File paths stop working.

    • E. 

      Missing or not-ported extensions.