PHP Introduction
- What will be the output of the following PHP code?
<?php
$State = "Chennai";
switch ($State) {
case "Mumbai":
echo "I love Mumbai. ";
case "Chennai":
echo "I love Chennai. ";
case "Rajshathan":
echo "I love Rajshatan. "; }
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.
- Which of the looping statements is/are supported by PHP?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
for each loop, do-while loop, while loop and for loop of the looping statements are supported by PHP.
- What will be the output of the following PHP code?
<?php
$user = array("Ats ", "Ajit ", "Rahul ", "Aju ");
for ($str=0; $str < count($user); $str++) {
if ($user[$str] == "Rahul ") continue;
printf ($user[$str]);
}
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.
- If $n = 25 what will be returned when (($n == 25) ? 5 : 1) is executed?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .
- What is the value of $a and $b after the function call?
<?php
function doSomething(&$argument)
{
$Result = $argument;
$argument += 1;
return $Result;
}
$n = 5;
$m = doSomething($n);
echo "n = " . $n . " and m = " . $m;
?>
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
$n is 6 and $m is 5. The former because $argument is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.