25 quizzes found.

What does the following function do, when passed two integer values for $p and $q?

<?phpfunction magic($p, $q) { return ($q == 0) ? $p : magic($q, $p % $q);}?>
  1. Loops infinitely
  2. Switches the values of $p and $q
  3. Determines if they are both even or odd
  4. Determines the greatest common divisor between them
  5. Calculates the modulus between the two

Choose 1 answers

What is the output of the following?

<?php$a = 20;function myfunction($b) {$a = 30;global $a, $c;return $c = ($b + $a);}print myfunction(40) + $c;?>
  1. 120
  2. Syntax Error
  3. 60
  4. 70

Choose 1 answers

What would you replace ??????? with, below, to make the string Hello, World! be displayed?

<?phpfunction myfunction() { ???????print $string;}myfunction("Hello, World!");?>
  1. There is no way to do this
  2. $string = $argv[1];
  3. $string = $_ARGV[0];
  4. list($string) = func_get_args();
  5. $string = get_function_args()

Choose 1 answers

What is the output of the following function?

<?phpfunction &find_variable(&$one, &$two, &$three) {if($one > 10 && $one < 20) return $one;if($two > 10 && $two < 20) return $two;if($three > 10 && $three < 20) return $three;}$one = 2;$two = 20;$three = 15;$var = &find_variable($one, $two, $three);$var++;print "1: $one, 2: $two, 3: $three";?>
  1. 1: 2, 2: 20, 3: 15
  2. 1: 3, 2:21, 3:16
  3. 1: 2, 2:21, 3:15
  4. 1: 3, 2: 20, 3: 15
  5. 1: 2, 2: 20, 3: 16

Choose 1 answers

Assinging $var with &, the $three variable returned by the function will be incremented with $var

What is wrong with the following code?

<?phpfunction duplicate($obj) {$newObj = $obj;return $newObj;}$a = new MyClass();$a_copy = duplicate($a);$a->setValue(10);$a_copy->setValue(20);?>
  1. You must use return &$newObj instead
  2. There is nothing wrong with this code
  3. duplicate() must accept its parameter by reference
  4. You must use the clone operator to make a copy of an object
  5. duplicate() must return a reference

Choose 1 answers