- Any variables declared in PHP must begin with a ?
- A. .
B. #
C. &
D. $
Ans : D
Explanation: Any variables declared in PHP must begin a dollar sign ($)
- A variable can have __?
- A. long descriptive names
B. short names
C. Both A and B
D. None of the above
Ans : C
Explanation: A variable can have long descriptive names (like $factorial, $even_nos) or short names (like $n or $f or $x)
3. A variable name can only contain ____________?
- A. alphanumeric characters
B. underscores
C. Both A and B
D. None of the above
Ans : C
Explanation: A variable name can only contain alphanumeric characters and underscores in their name.
4. Variable names in PHP must start with ?
A. letter
B. underscore
C. no numbers
D. All of the above
Ans : D
Explanation: variable names in PHP must start with a letter or underscore and should not start with numbers.
5. PHP variables are case-sensitive?
- A. True
B. False
C. For “sum” variable it is case-sensitive
D. None of the above
Ans : A
Explanation: PHP variables are case-sensitive,
6. How many variable scope are there in php?
- A. 2
B. 3
C. 1
D. 4
Ans : B
Explanation: PHP has three variable scopes: Local, Global and static variable scope.
7. What will be the output of the following PHP code?
<?php
$x = 1;
$y = 2;
$z = "$x + $y";
echo "$z";
?<
- A. $x + $y
B. 3
C. 1+2
D. 12
Ans : C
Explanation: Variable z will store 1 + 2 because 1 + 2 is given in double-quotes.
8. What will be the output of the following PHP code?
<?php
$x = 3.3;
$y = 2;
echo $x % $y;
?>
A. 1.3
B. 1
C. 0
D. Error
Ans : B
Explanation: % is the modulo operator. Unlike in C, we can use it to get a reminder or floating-point numbers in PHP.
9. What will be the output of the following PHP code?
<?php
$a = 1;
$b = 2;
$c = 3;
echo ($a % ($b) + $c);
?>
- A. 2
B. 3
C. 4
D. 5
Ans : A
Explanation: The innermost bracket is evaluated only variable b it is as good as not using brackets.
10. What will be the output of the following PHP code?
<?php
$a = 1;
$b = 2;
$c = 3;
echo ($a * (($b) - $c));
?>
- A. 1
B. -1
C. 2
D. -2
Ans : B
Explanation: The innermost bracket is evaluated first since it covers only variable B, it is as good as not using brackets.