Basic PHP Quiz 2

Basic PHP Quiz 2

10 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the difference between print() and echo()?

  1. print() can be used as part of an expression, while echo() can't
  2. echo() can be used as part of an expression, while print() can't
  3. echo() can be used in the CLI version of PHP, while print() can't
  4. print() can be used in the CLI version of PHP, while echo() can't
Question 2 Multiple Choice (Single Answer)

What is displayed when the following script is executed?

define(myvalue, "10");
$myarray[10] = "Dog";
$myarray[] = "Human";
$myarray['myvalue'] = "Cat";
$myarray["Dog"] = "Cat";
print "The value is: ";
print $myarray[myvalue]."\\n";
  1. The value is: Dog
  2. The value is: Cat
  3. The value is: Human
  4. The value is: 10
Question 3 Multiple Choice (Single Answer)

Which of the following is not valid PHP code?

  1. $_10
  2. ${"MyVar"}
  3. &$something
  4. $10_somethings
Question 4 Multiple Choice (Single Answer)

Which of the following tags is not a valid way to begin and end a PHP code block?

  1. <% %>
  2. <?php ?>
  3. <?= ?>
  4. <! !>
Question 5 Multiple Choice (Single Answer)

When turned on, __________ will __________ your script with different variables from HTML forms and cookies.

  1. show_errors, enable
  2. show_errors, show
  3. register_globals, enhance
  4. register_globals, inject
Question 6 Multiple Choice (Single Answer)

What is the value of $result in the following PHP code?

function timesTwo($int)
{
  $int = $int * 2;
}

$int = 2;

$result = timesTwo($int);
  1. 0
  2. 2
  3. 4
  4. NULL
Question 7 Multiple Choice (Single Answer)

Which of the following prints ‘text/xml’?

  1. print substr($text, strchr($text, ':'));
  2. print substr($text, strchr($text, ':') 1);
  3. print substr($text, strpos($text, ':') 1);
  4. print substr($text, strpos($text, ':') 2);
Question 8 Multiple Choice (Single Answer)

What does echo count (“123?) print out?

  1. 3
  2. false
  3. null
  4. 1
Question 9 Multiple Choice (Single Answer)

Which of the following snippets prints a representation of 42 with two decimal places?

  1. printf("%.2d\n", 42);
  2. printf("%1.2f\n", 42);
  3. printf("%1.2u\n", 42);
  4. none of the above
Question 10 Multiple Choice (Multiple Answers)

Which of the following expressions multiply the value of the integer variable $a by 4?

  1. $a *= pow (2, 2);
  2. $a >>= 2;
  3. $a <<= 2;
  4. $a = $a $a;