Zend PHP5 Certification Mock Exam Sample Questions — 1

This is the first part of the explanation exam questions to test Zend PHP5 with the correct (imho) answers and useful links on manuals.

If you have additional thoughts please use comments.

1. Which of the following tags are an acceptable way to begin a PHP Code block? (Choose 4 answers)

  1. <SCRIPT LANGUAGE=»php»>
  2. <!
  3. <%
  4. <?php
  5. <?

Answer: A, C, D, E
http://php.net/manual/en/language.basic-syntax.phpmode.php

2. Which of the following are valid PHP variables? (Choose 4 answers)

  1. @$foo
  2. &$variable
  3. ${0×0}
  4. $variable
  5. $0×0

Answer: A, B, C, D
http://php.net/manual/en/language.variables.php

3. What is the best way to iterate and modify every element of an array using PHP 5? (Choose 1 answer)

  1. You cannot modify an array during iteration
  2. for($i = 0; $i < count($array); $i++) { /* … */ }
  3. foreach($array as $key => &$val) { /* … */ }
  4. foreach($array as $key => $val) { /* … */ }
  5. while(list($key, $val) = each($array)) { /* … */

Answer: C
http://php.net/manual/en/control-structures.foreach.php: As of PHP 5, you can easily modify array's elements by preceding $value with &. This will assign reference instead of copying the value.

4. What is the output of the following PHP code? (Choose 1 answer)
<?php
define('FOO', 10);
$array = array(10 => FOO, "FOO" => 20);
print $array[$array[FOO]] * $array["FOO"];
?>

  1. FOO
  2. 100
  3. 200
  4. 20
  5. 10

Answer: C
http://www.php.net/manual/en/function.define.php, http://php.net/manual/en/language.constants.php, FOO is constant, but “FOO” is string

5. What is the output of the following PHP script? (Choose 1 answer)
<?php
$a = 1;
$b = 2.5;
$c = 0xFF;
$d = $b + $c;
$e = $d * $b;
$f = ($d + $e) % $a;
print ($f + $e);
?>

  1. 643.75
  2. 432
  3. 643
  4. 257
  5. 432.75

Answer: A
http://en.wikipedia.org/wiki/Hexadecimal, http://www.php.net/manual/en/language.operators.arithmetic.php

6. What combination of boolean values for $a, $b, $c, and $d will result in the variable $number being equal to 3? (Choose 1 answer)
<?php
$a = null;
$b = null;
$c = null;
$d = null;
if($a && !$b) {
   if(!!$c && !$d) {
      if($d && ($a || $c)) {
         if(!$d && $b) {
            $number = 1;
         } else {
            $number = 2;
         }
      } else {
         $number = 3;
      }
   } else {
      $number = 4;
   }
} else {
   $number = 5;
}
?>

  1. false, true, true, true
  2. true, false, true, false
  3. true, true, false, false
  4. false, true, true, false
  5. false, false, true, false

Answer: B
http://www.php.net/manual/en/language.operators.logical.php : $a && $b – And – TRUE if both $a and $b are TRUE -> ($a && !$b) TRUE then $a is TRUE and $b is FALSE.

7. What is the output of the following code? (Choose 1 answer)
<?php
$string = "111221";
for($i = 0; $i < strlen($string); $i++) {
   $current = $string[$i];
   $count = 1;
   while(isset($string[$i + $count]) && ($string[$i + $count] == $current)) $count++;
   $newstring .= "$count{$current}";
   $i += $count-1;
}
print $newstring;
?>

  1. 312211
  2. 3312212
  3. 11221221
  4. 221131
  5. 3211122

Answer: A
Just executing while loop once you will get the answer.

8. What is the best way to ensure that a user-defined function is always passed an object as its single parameter? (Choose 1 answer)

  1. function myfunction(stdClass $a)
  2. function myfunciton($a = stdClass)
  3. Use is_object() within the function
  4. There is no way to ensure the parameter will be an object
  5. function myfunction(Object $a)

Answer: C
http://php.net/manual/en/function.is-object.php

9. What does the following function do, when passed two integer values for $p and $q? (Choose 1 answer)
<?php
function 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

Answer: D

10. The ____ operator is used to test if two values are identical in every way. (Choose 1 answer)

  1. !==
  2. instanceof
  3. =
  4. ==
  5. ===

Answer: E
http://www.php.net/manual/en/language.operators.comparison.php

11. What would go in place of ?????? below to make this script execute without a fatal error? (Choose 3 answers)

  1. quit();
  2. die();
  3. stop();
  4. __halt_compiler();
  5. exit();

Answer: B, D, E
http://ru.php.net/manual/en/function.die.php, http://php.net/manual/en/function.halt-compiler.php, http://ru.php.net/manual/en/function.exit.php

12. What is the output of the following? (Choose 1 answer)
<?php
$a = 010;
$b = 0xA;
$c = 2;
print $a + $b + $c;
?>

  1. 20
  2. 22
  3. 18
  4. $a is an invalid value
  5. 2

Answer: A
http://en.wikipedia.org/wiki/Octal, http://en.wikipedia.org/wiki/Hexadecimal

13. What is the output of the following? (Choose 1 answer)
<?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

Answer: A
http://php.net/manual/en/language.variables.scope.php

14. What would you replace ??????? with, below, to make the string Hello, World! be displayed? (Choose 1 answer)
<?php
function 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()

Answer:D
http://ru.php.net/manual/en/function.func-get-args.php

15. What is the output of the following function? (Choose 1 answer)
<?php
function &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

Answer: E
http://www.php.net/manual/en/functions.returning-values.php, http://www.php.net/manual/en/language.references.return.php
http://www.php.net/manual/en/language.references.pass.php

16. For an arbitrary string $mystring, which of the following checks will correctly determine if the string PHP exists within it? (Choose 1 answer)

  1. if(strpos($mystring, «PHP») !== false)
  2. if(!strpos($mystring,»PHP»))
  3. if(strpos($mystring, «PHP») === true)
  4. if(strloc($mystring, «PHP») == true)
  5. if(strloc($mystring, «PHP») === false)

Answer: A
http://php.net/manual/en/function.strpos.php: This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or «».
http://www.php.net/manual/en/language.types.boolean.php
http://www.php.net/manual/en/language.operators.comparison.php

17. What are the values of $a in $obj_one and $obj_two when this script is executed? (Choose 1 answer)
<?php
class myClass {
   private $a;
   public function __construct() {
      $this->a = 10;
   }
   public function printValue() {
      print "The Value is: {$this->a}\n";
   }
   public function changeValue($val, $obj = null) {
      if(is_null($obj)) {
         $this->a = $val;
      } else {
         $obj->a = $val;
      }
   }
   public function getValue() {
      return $this->a;
   }
}
$obj_one = new myClass();
$obj_two = new myClass();
$obj_one->changeValue(20, $obj_two);
$obj_two->changeValue($obj_two->getValue(), $obj_one);
$obj_two->printValue();
$obj_one->printValue();
?>

  1. 10,20
  2. You cannot modify private member variables of a different class
  3. 20,20
  4. 10,10
  5. 20,10

Answer: C
http://php.net/manual/en/language.oop5.visibility.php
http://php.net/manual/en/language.oop5.references.php

18. What are the three access modifiers that you can use in PHP objects? (Choose 3 answers)

  1. protected
  2. public
  3. static
  4. private
  5. final

Answer: A, B, D
http://php.net/manual/en/language.oop5.visibility.php

19. When checking to see if two variables contain the same instance of an object, which of the following comparisons should be used? (Choose 1 answer)

  1. if($obj1->equals($obj2) && ($obj1 instanceof $obj2))
  2. if($obj1->equals($obj2))
  3. if($obj1 === $obj2)
  4. if($obj1 instance of $obj2)
  5. if($obj1 == $obj2)

Answer: D
http://php.net/manual/en/internals2.opcodes.instanceof.php, http://php.net/manual/en/language.operators.type.php

20. In PHP 5 you can use the ______ operator to ensure that an object is of a particular type. You can also use_______ in the function declaration. (Choose 1 answer)

  1. instanceof, is_a
  2. instanceof, type-hinting
  3. type, instanceof
  4. ===, type-hinting
  5. ===, is_a

Answer: B
http://php.net/manual/en/internals2.opcodes.instanceof.php, http://php.net/manual/en/language.oop5.typehinting.php

21. What is wrong with the following code? (Choose 1 answer)
<?php
function 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

Answer: D
http://php.net/manual/en/language.oop5.cloning.php

22. How can you modify the copy of an object during a clone operation? (Choose 1 answer)

  1. Put the logic in the object's constructor to alter the values
  2. Implment your own function to do object copying
  3. Implement the object's __clone() method
  4. Implement __get() and __set() methods with the correct logic
  5. Implement the __copy() method with the correct logic

Answer: C
http://php.net/manual/en/language.oop5.cloning.php

23. What is the primary difference between a method declared as static and a normal method? (Choose 1 answer)

  1. Static methods can only be called using the :: syntax and never from an instance
  2. Static methods do not provide a reference to $this
  3. Static methods cannot be called from within class instances
  4. Static methods don't have access to the self keyword
  5. There is no functional difference between a static and non-static method

Answer: A
http://php.net/manual/en/language.oop5.static.php: “Declaring class properties or methods as static makes them accessible without needing an instantiation of the class.” looks more primary then “Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside the method declared as static.”.

24. What is the output of the following script? (Choose 1 answer)
<?php
class ClassOne {
   protected $a = 10;
   public function changeValue($b) {
      $this->a = $b;
   }
}
class ClassTwo extends ClassOne {
   protected $b = 10;
   public function changeValue($b) {
      $this->b = 10;
      parent::changeValue($this->a + $this->b);
   }
   public function displayValues() {
      print "a: {$this->a}, b: {$this->b}\n";
   }
}
$obj = new ClassTwo();
$obj->changeValue(20);
$obj->changeValue(10);
$obj->displayValues();
?>

  1. a: 30, b: 30
  2. a: 30, b: 20
  3. a: 30, b: 10
  4. a: 20, b: 20
  5. a: 10, b: 10

Answer: C
http://php.net/manual/en/language.oop5.visibility.php

25. The ______ keyword is used to indicate an incomplete class or method, which must be further extended and/or implemented in order to be used. (Choose 1 answer)

  1. final
  2. protected
  3. incomplete
  4. abstract
  5. implements

Answer: D
http://php.net/manual/en/language.oop5.abstract.php

26. To ensure that a given object has a particular set of methods, you must provide a method list in the form of an________ and then attach it as part of your class using the ________ keyword. (Choose 1 answer)

  1. array, interface
  2. interface, implements
  3. interface, extends
  4. instance, implements
  5. access-list, instance

Answer: B
http://php.net/manual/en/language.oop5.interfaces.php

27. Type-hinting and the instanceof keyword can be used to check what types of things about variables? (Choose 3 answers)

  1. If a particular child class extends from it
  2. If they are an instance of a particular interface
  3. If they are an abstract class
  4. If they have a particular parent class
  5. If they are an instance of a particular class

Answer: B, D, E
http://php.net/manual/en/language.operators.type.php: Example #4, Example #2, Example #1 respectively

28. In PHP 5's object model, a class can have multiple ______ but only a single direct. (Choose 1 answer)

  1. None of the above
  2. interfaces, child
  3. children, interface
  4. interfaces, parent
  5. parents, interface

Answer: D
http://php.net/manual/en/language.oop5.interfaces.php: Example #3 Multiple interface inheritance, http://php.net/manual/en/keyword.extends.php: An extended class is always dependent on a single base class, that is, multiple inheritance is not supported.

29. What three special methods can be used to perform special logic in the event a particular accessed method or member variable is not found? (Choose 3 answers)

  1. __get($variable)
  2. __call($method, $params)
  3. __get($method)
  4. __set($variable, $value)
  5. __call($method)

Answer: A, B, D
http://php.net/manual/en/language.oop5.overloading.php

30. The _______ method will be called automatically when an object is represented as a string. (Choose 1 answer)

  1. getString()
  2. __get()
  3. __value()
  4. __toString()
  5. __getString()

Answer: D
http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring

31. When an object is serialized, which method will be called, automatically, providing your object with an opportunity to close any resources or otherwise prepare to be serialized? (Choose 1 answer)

  1. __destroy()
  2. __serialize()
  3. __destruct()
  4. __shutdown()
  5. __sleep()

Answer: E
http://php.net/manual/en/function.serialize.php

32. What is the output of the following code? (Choose 1 answer)
<?php
class MyException extends Exception {}
class AnotherException extends MyException {}
class Foo {
   public function something() {
      throw new AnotherException();
   }
   public function somethingElse() {
      throw new MyException();
   }
}
$a = new Foo();
try {
   try {
      $a->something();
   } catch(AnotherException $e) {
      $a->somethingElse();
   } catch(MyException $e) {
      print "Caught Exception";
   }
} catch(Exception $e) {
   print "Didn't catch the Exception!";
}
?>

  1. «Caught Exception» followed by «Didn't catch the Exception!»
  2. A fatal error for an uncaught exception
  3. «Didn't catch the Exception!»
  4. «Didn't catch the Exception!» followed by a fatal error
  5. «Caught Exception»

Answer: C
http://php.net/manual/en/language.exceptions.php, http://stackoverflow.com/questions/2586608/confused-by-this-php-exception-try-catch-nesting

33. Which two internal PHP interfaces provide functionality which allow you to treat an object like an array? (Choose 2 answers)

  1. iteration
  2. arrayaccess
  3. objectarray
  4. iterator
  5. array

Answer: B, D
http://php.net/manual/en/class.arrayaccess.php, http://php.net/manual/en/class.iterator.php

34. Which php.ini directive should be disabled to prevent the execution of a remote PHP script via an include or require construct? (Choose 1 answer)

  1. You cannot disable remote PHP script execution
  2. curl.enabled
  3. allow_remote_url
  4. allow_url_fopen
  5. allow_require

Answer: D
http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

35. When attempting to prevent a cross-site scripting attack, which of the following is most important? (Choose 1 answer)

  1. Not writing Javascript on the fly using PHP
  2. Filtering Output used in form data
  3. Filtering Output used in database transactions
  4. Writing careful Javascript
  5. Filtering all input

Answer: E

36. Which of the following php.ini directives should be disabled to improve the outward security of your application? (Choose 4 answers)

  1. safe_mode
  2. magic_quotes_gpc
  3. register_globals
  4. display_errors
  5. allow_url_fopen

Answer: B, C, D, E
http://php.net/manual/en/features.safe-mode.php

37. Which of the following list of potential data sources should be considered trusted? (Choose 1 answer)

  1. None of the above
  2. $_ENV
  3. $_GET
  4. $_COOKIE
  5. $_SERVER

Answer: A

38. What is the best way to ensure the distinction between filtered / trusted and unfiltered / untrusted data? (Choose 1 answer)

  1. None of the above
  2. Never trust any data from the user
  3. Enable built-in security features such as magic_quotes_gpc and safe_mode
  4. Always filter all incoming data
  5. Use PHP 5's tainted mode

Answer: D
http://devzone.zend.com/article/1113

39. Consider the following code, what potential security hole would this code snippet produce: (Choose 1 answer)
<?php
session_start();
if(!empty($_REQUEST['id']) && !empty($_REQUEST['quantity'])) {
   $id = scrub_id($_REQUEST['id']);
   $quantity = scrub_quantity($_REQUEST['quantity'])
   $_SESSION['cart'][] = array('id' => $id, 'quantity' => $quantity)
}
/* .... */
?>

  1. Cross-Site Scripting Attack
  2. There is no security hole in this code
  3. Code Injection
  4. SQL Injection
  5. Cross-Site Request Forgery

Answer: E
http://en.wikipedia.org/wiki/Cross-site_request_forgery

40. What is the best measure one can take to prevent a cross-site request forgery? (Choose 1 answer)

  1. Disallow requests from outside hosts
  2. Add a secret token to all form submissions
  3. Turn off allow_url_fopen in php.ini
  4. Filter all output
  5. Filter all input

Answer:B
http://en.wikipedia.org/wiki/Cross-site_request_forgery#Prevention

41. Consider the following code, which of the following values of $_GET['url'] would cause session fixation? (Choose 1 answer)
<?php
header("Location: {$_GET['url']}");
?>

  1. Session Fixation is not possible with this code snippet
  2. http://www.zend.com/?PHPSESSID=123
  3. PHPSESSID%611243
  4. Set-Cookie%3A+PHPSESSID%611234
  5. http%3A%2F%2Fwww.zend.com%2F%0D%0ASet-Cookie%3A+PHPSESSID%611234

Answer: B
http://www.php.net/manual/en/session.idpassing.php

42. When implementing a permissions system for your Web site, what should always be done with regards to the session? (Choose 1 answer)

  1. None of the above
  2. You should not implement permission systems using sessions
  3. Sessions should be cleared of all data and re-populated
  4. The session key should be regenerated
  5. The session should be destroyed

Answer: D
http://www.php.net/manual/en/function.session-regenerate-id.php

43. Which of the following is not valid syntax for creating a new array key? (Choose 1 answer)

  1. $a[] = «value»;
  2. $a{} = «value»;
  3. $a[0] = «value»;
  4. $a{0} = «value»;
  5. $a[$b = 0] = «value»;

Answer: B
http://php.net/manual/en/language.types.array.php

44. Which of the following functions will sort an array in ascending order by value, while preserving key associations? (Choose 1 answer)

  1. asort()
  2. usort()
  3. krsort()
  4. ksort()
  5. sort()

Answer: A
http://php.net/manual/en/function.asort.php — sort an array and maintain index association.

45. What is the output of the following code block? (Choose 1 answer)
<?php
$a = "The quick brown fox jumped over the lazy dog.";
$b = array_map("strtoupper", explode(" ", $a));
foreach($b as $value) {
   print "$value ";
}
?>

  1. THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
  2. A PHP Error
  3. Array Array Array Array Array Array Array Array Array

Answer: A
http://php.net/manual/en/function.array-map.php

46. Which from the following list is not an appropriate use of an array? (Choose 1 answer)

  1. As a list
  2. All of these uses are valid
  3. As a Lookup Table
  4. A Stack
  5. As a hash table

Answer: B
http://php.net/manual/en/language.types.array.php: This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more.

47. What is the output of this code snippet? (Choose 1 answer)
<?php
$a = array(0.001 => 'b', .1 => 'c');
print_r($a);
?>

  1. An empty array
  2. 0.001 => 'b', .1 => c
  3. 0 => 'c'
  4. '0.001' => 'b', '0.1' => c'
  5. A Syntax Error

Answer: C
http://php.net/manual/en/language.types.array.php :Floats in key are truncated to integer.

48. Which of the following functions could be used to break a string into an array? (Choose 3 answers)

  1. array_split()
  2. split()
  3. string_split()
  4. preg_match_all()
  5. explode()

Answer: B, D, E
http://ru.php.net/manual/en/function.split.php, http://ru.php.net/manual/en/function.preg-match-all.php, http://ru.php.net/manual/en/function.explode.php

49. If you wanted a variable containing the letters A through Z, that allowed you to access each letter independently, which of the following approaches could you use? (Choose 3 answers)

  1. $str = «ABCDEFGHIJKLMNOPQRSTUVWXYZ»;
  2. range('A', 'Z');
  3. explode(«», «ABCDEFGHIJKLMNOPQRSTUVWXYZ»);
  4. You would use the ALPHA_ARRAY constant
  5. None of the above

Answer: A, B, C (but C is error in mock test, see manual about delimeter)
http://ru.php.net/manual/en/function.range.php, http://ru.php.net/manual/en/function.explode.php (Warning: explode(): Empty delimiter.)

50. What is the output of the following code block? (Choose 1 answer)
<?php
$array = array(1 => 0, 2, 3, 4);
array_splice($array, 3, count($array), array_merge(array('x'), array_slice($array, 3)));
print_r($array);
?>

  1. 1 => 1, 2 => 2, 3 => x, 4=> 4
  2. 0 => 1, 2 => 2, 3 => 3, 4 => 4, x => 3
  3. 0 => 0, 1=> 2, 2 => 3, 3 => x, 4 => 4
  4. 0 => x, 1 => 0, 2 => 1, 3=> 2, 4=>3
  5. 1 => 1, 3 => x, 2 => 2, 4 => 4

Answer: C
http://ru.php.net/manual/en/function.array-slice.php, http://ru.php.net/manual/en/function.array-merge.php, http://ru.php.net/manual/en/function.array-splice.php

51. Which function would you use to add an element to the beginning of an array? (Choose 1 answer)

  1. array_shift()
  2. array_push();
  3. $array[0] = «value»;
  4. array_unshift()
  5. array_pop();

Answer: D
http://ru.php.net/manual/en/function.array-unshift.php

52. Which key will not be displayed from the following code block? (Choose 1 answer)
<?php
$array = array('a' => 'John',
'b' => 'Coggeshall',
'c' => array('d' => 'John',
'e' => 'Smith'));
function display($item, $key) {
   print "$key => $item\n";
}
array_walk_recursive($array, "display");
?>

  1. d
  2. c
  3. b
  4. a
  5. They all will be displayed

Answer: B
http://ru.php.net/manual/en/function.array-walk-recursive.php

53. What is the result of the following code snippet? (Choose 1 answer)
<?php
$array = array('a' => 'John',
'b' => 'Coggeshall',
'c' => array('d' => 'John',
'e' => 'Smith'));
function something($array) {
   extract($array);
   return $c['e'];
}
print something($array);
?>

  1. Smith
  2. A PHP Warning
  3. Coggeshall
  4. NULL
  5. Array

Answer: A
http://ru.php.net/manual/en/function.extract.php

54. What should go in the missing line ????? below to produce the output shown? (Choose 1 answer)
<?php
$array_one = array(1,2,3,4,5);
$array_two = array('A', 'B', 'C', 'D', 'E');
???????
print_r($array_three);
?>

Result:
Array
(
[5] => A
[4] => B
[3] => C
[2] => D
[1] => E
)

  1. $array_three = array_merge(array_reverse($array_one), $array_two);
  2. $array_three = array_combine($array_one, $array_two);
  3. $array_three = array_combine(array_reverse($array_one), $array_two);
  4. $array_three = array_merge($array_one, $array_two);
  5. $array_three = array_reverse($array_one) + $array_two;

Answer: C
http://ru.php.net/manual/en/function.array-combine.php, http://ru.php.net/manual/en/function.array-reverse.php

55. Which of the following functions are used with the internal array pointer to accomplish an action? (Choose 4 answers)

  1. key
  2. forward
  3. prev
  4. current
  5. next

Answer: A, C, D, E
http://php.net/manual/en/function.key.php, http://php.net/manual/en/function.prev.php, http://php.net/manual/en/function.current.php, http://php.net/manual/en/function.next.php

56. Given the following array, the fastest way to determine the total number a particular value appears in the array is to use which function: (Choose 1 answer)
$array = array(1,1,2,3,4,4,5,6,6,6,6,3,2,2,2);

  1. array_total_values
  2. array_count_values
  3. A foreach loop
  4. count
  5. a for loop

Answer: B
http://ru.php.net/manual/en/function.array-count-values.php

57. The ____ construct is particularly useful to assign your own variable names to values within an array. (Choose 1 answer)

  1. array_get_variables
  2. current
  3. each
  4. import_variables
  5. list

Answer: E
http://ru.php.net/manual/en/function.list.php

58. The following code snippet displays what for the resultant array? (Choose 1 answer)
<?php
$a = array(1 => 0, 3 => 2, 4 => 6);
$b = array(3 => 1, 4 => 3, 6 => 4);
print_r(array_intersect($a, $b));
?>

  1. 1 => 0
  2. 1 => 3, 3 => 1, 4 => 3
  3. 3 => 1, 3=> 2, 4 => 3, 4=> 6
  4. 1 => 0, 3 => 2, 4 => 6
  5. An empty Array

http://ru.php.net/manual/en/function.array-intersect.php

59. Which of the following are not valid ways to embed a variable into a string? (Choose 1 answer)

  1. $a = «Value: $value->getValue()»;
  2. $a = «Value: {$value}»;
  3. $a = 'Value: $value';
  4. $a = «Value: $value»;
  5. $a = «Value: {$value['val']}»;

Answer: A, C
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double

60. What variable reference would go in the spots indcated by ????? in the code segment below? (Choose 1 answer)
<?php
$msg = "The Quick Brown Foxed Jumped Over the Lazy Dog";
$state = true;
$retval = "";
for($i = 0; (isset(??????)); $i++) {
   if($state) {
      $retval .= strtolower(?????);
   } else {
      $retval .= strtoupper(?????);
   }
$state = !$state;
}
print $retval;
?>

  1. $msg{$i}
  2. ord($msg);
  3. chr($msg);
  4. substr($msg, $i, 2);

Answer: A
http://ru.php.net/manual/en/function.isset.php

Комментариев: 4

  • 17.11.2011 Mulder:

    Вопрос №19: Какой код надо использовать, чтобы удостовериться, что две переменные ссылаются на один и тот же объект. Правильный ответ С. Приведенный совет служит для проверки принадлежности объекта к определенному классу/интерфейсу.

  • 17.11.2011 Mulder:

    23. What is the primary difference between a method declared as static and a normal method?

    Ответ А с натяжкой можно было бы считать правдой, если бы не вторая часть предложения. Статический метод легко вызывается из объектного метода, например через self::, если оба метода находятся в одном классе.

    Правильный ответ B.

  • 19.10.2012 Nicolo:

    Hello,

    I have found a web site that contain several answer and php training test

    http://www.php-certifications.com

    It covers all categorys of the Zend PHP 5.3 Certification :

    PHP Bases

    Streams and Network Programming

    Databases and SQL

    XML and Web Services

    Object Oriented Programming

    Security

    Strings and Patterns

    Web Features

    PHP 4/5 Differences

    Functions

    Arrays

    Design and Theory


Добавление комментария:

 css.php