Basic PHP Quiz 1
A quiz covering fundamental PHP concepts including syntax, variables, functions, arrays, operators, and control structures
Questions
What PHP stands for?
- Hypertext Preprocessor
- Pre Hypertext Processor
- Pre Hyper Processor
- Pre Hypertext Process
How does the identity operator === compare two values?
- It converts them to a common compatible data type and then compares the resulting values
- It returns True only if they are both of the same type and value
- If the two values are strings, it performs a lexical comparison
- It bases its comparison on the C strcmp function exclusively
Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?
- When the parameter is Boolean
- When the function is being declared as a member of a class
- When the parameter is being declared as passed by reference
- When the function contains only one parameter
Variables always start with a ........ in PHP
- Pond-sign
- Yen-sign
- Dollar-sign
- Euro-sign
What is the value displayed when the following is executed? Assume that the code was executed using the following URL:
testscript.php?c=25
- 25
- 10
- -5
- 0
Choose the appropriate function declaration for the user-defined function is_leap(). Assume that, if not otherwise defined, the is_leap function uses the year 2000 as a default value:
{
$is_leap = (!($year %4) && (($year % 100) ||
!($year % 400)));
return $is_leap;
}
var_dump(is_leap(1987)); /* Displays false /
var_dump(is_leap()); / Displays true */
- function is_leap($year = 2000)
- function is_leap($year default 2000)
- function is_leap($year)
- is_leap($year default 2000)
What is the best way to iterate through the $myarray array, assuming you want to modify the value of each element as you do?
$myarray = array ("My String","Another String","Hi, Mom!");
- Using a for loop
- Using a foreach loop
- Using a while loop
- Using a do..while loop
Which language construct can best represent the following series of if conditionals?
if($a == 'a') {
somefunction();
} else if ($a == 'b') {
anotherfunction();
} else if ($a == 'c') {
dosomething();
} else {
donothing();
}
- A switch statement without a default case
- A recursive function call
- A switch statement using a default case
- A while statement
What will the following script output?
$array = '0123456789ABCDEFG';
$s = '';
for ($i = 1; $i < 50; $i++) {
$s .= $array[rand(0,strlen ($array) - 1)];
}echo $s;
- A string of 50 random characters
- A string of 49 copies of the same character, because the random number generator
- A string of 49 random characters
- has not been initialized
What is the output of the following script?
$a = 10;
$b = 20;
$c = 4;
$d = 8;
$e = 1.0;
$f = $c + $d * 2;
$g = $f % 20;
$h = $b - $a + $c + 2;
$i = $h << $c;
$j = $i * $e;
print $j;
- 128
- 42
- 256
- 342