ExamVeda
Login
Home
21
What will be the output of the following PHP code ?
<?php
$one = "Hello";
$two = "World";
echo $one, $two;
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
Echo can print two variables which are seperated by a comma.
22
What will be the output of the following PHP code ?

<?php
$one = "Hello";
$two = "World";
echo "$one$two";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
Even though both the variables are inside the double-quotes, the value of the variable is substituted and then printed to the screen.
23
What will be the output of the following PHP code ?

<?php
$one = "Hello";
$two = "World";
echo "$one"+"$two";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
In the given PHP code, the concatenation operator (.) should be used instead of the addition operator (+) to concatenate strings. When using the addition operator with strings, PHP will attempt to convert the strings to numbers for addition. If a string cannot be converted to a number, it will be treated as 0.

So, in this code, "$one" and "$two" are treated as numeric strings, which will be converted to 0 when converted to numbers. Therefore, the output of the expression "$one" + "$two" will be 0.

Option A: HelloWorld is incorrect because the correct output is 0, not the concatenation of the two strings.
Option B: Hello+World is incorrect because the correct output is 0, not the two strings separated by a plus sign.
Option D: Error is incorrect because there is no syntax error in the code, but the output is 0
24
What will be the output of the following PHP code ?
<?php
echo "This is India";
?>
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
25
What will be the output of the following PHP code ?
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo "My car is a {$cars[0]}";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
In the echo statement the {$cars[0]} is replaced by the 1st element in cars that is Volvo.
26
What will be the output of the following PHP code ?
<?php
print "echo hello world";
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The print statement will print what ever is present inside the double-quotes.
27
What will be the output of the following PHP code ?
<?php
$one = 1;
print($one);
print $one;
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
Print can be used with or without parantheses.
28
What will be the output of the following PHP code ?
<?php
$cars = array("Volvo", "BMW", "Toyota");
print $cars[2];
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
Print statement can be used to output a specific array member.
29
What will be the output of the following PHP code ?
<?php
$one = "one";
$two = "two";
print($one$two);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The above syntax will produce an error, unlike the echo statement.
30
What will be the output of the following PHP code ?
<?php
$one = "one";
$two = "two";
print($one,$two);
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The above syntax will produce an error, unlike the echo statement.