ExamVeda
Login
Home
11
What will be the output of the following code?
<?php 
$foo = 'Bob';
$bar = &$foo;        
$bar = "My name is $bar";
echo $bar;
echo $foo;
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The $bar = &$foo; line will reference $foo via $bar.
12
Which of the following PHP statements will output Hello World on the screen?
1. echo (“Hello World”);
2. print (“Hello World”);
3. printf (“Hello World”);
4. sprintf (“Hello World”);
Discuss
Answer & Solution
Answer: Option B
Solution:
echo(), print() and printf() all three can be used to output a statement onto the screen. The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.
13
What will be the output of the following PHP code?
<?php
$color = "maroon";
$var = $color[2];
echo "$var";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
PHP treats strings in the same fashion as arrays, allowing for specific characters to be accessed via array offset notation.
14
What will be the output of the following PHP code?
<?php
$score = 1234;
$scoreboard = (array) $score;
echo $scoreboard[0];
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The (array) is a cast operator which is used for converting values from other data types to array.
15
What will be the output of the following PHP code?
<?php
$total = "25 students";
$more = 10;
$total = $total + $more;
echo "$total";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The integer value at the beginning of the original $total string is used in the calculation. However if it begins with anything but a numerical value, the value will be 0.
16
Which of the below statements is equivalent to $add += $add ?
Discuss
Answer & Solution
Answer: Option B
Solution:
a += b is an addition assignment whose outcome is a = a + b. Same can be done with subtraction,multiplication,division etc.
17
Which statement will output $x on the screen?
Discuss
Answer & Solution
Answer: Option A
Solution:
A backslash is used so that the dollar sign is treated as a normal string character rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as escape character.
18
What will be the output of the following code?
<?php
function track() 
{
	static $count = 0;
	$count++;
	echo $count;
}
track();
track();
track();
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Because $count is static, it retains its previous value each time the function is executed.
19
What will be the output of the following PHP code?
<?php
$a = "clue";
$a .= "get";
echo "$a";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
.= is a concatenation-assignment. $a equals its current value concatenated with “get”.
20
What will be the output of the following PHP code?
<?php
$a = 5;
$b = 5;
span class="sys-fun">echo ($a === $b);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
=== operator returns 1 if $a and $b are equivalent and $a and $b have the same type.