17 quizzes found.

What is the best way to iterate and modify every element of an array using PHP 5?

  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)) { /* ... */}

Choose 1 answers

Which of the following is not valid syntax for creating a new array key?

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

Choose 1 answers

Which of the following functions will sort an array in ascending order by value, while preserving key associations?

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

Choose 1 answers

What is the output of the following code block?

<?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

Choose 1 answers

Which from the following list is not an approrpiate use of an array?

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

Choose 1 answers