
Q31
Q31 In PHP, the switch statement is used as an alternative to which other control structure?
if
while
for
foreach
Q32
Q32 What is the purpose of the break statement in PHP loops?
To pause the loop execution
To exit the loop
To skip the current iteration
To continue loop execution
Q33
Q33 In PHP, what will happen if you forget to increment the counter in a while loop?
The loop will run indefinitely
The loop will exit immediately
The loop will throw an error
The loop will skip iterations
Q34
Q34 Which looping structure is best for iterating over an associative array in PHP?
for
foreach
while
do-while
Q35
Q35 What will be the output of the following PHP code?
$i = 0;
while($i < 3) {
echo $i;
$i++;
}
?>
012
123
210
An error
Q36
Q36 Consider the following PHP code:
for ($i = 1; $i <= 5; $i++) {
if ($i == 3) {
continue;
}
echo $i;
}
?>
What will be the output?
1245
12345
1234
Error
Q37
Q37 Identify the error in this PHP foreach loop:
foreach($array as $value) {
echo $value
}
?>
Missing semicolon after echo
Syntax error in foreach
Missing $ before array
No error in the code
Q38
Q38 Spot the mistake in this PHP while loop:
$i = 0;
while ($i <= 5) {
echo $i
}
$i++;
?>
Infinite loop
Missing increment inside loop
Missing semicolon after echo
Syntax error in while
Q39
Q39 Find the error in this PHP code involving a for loop:
echo $i;
}
?>
Syntax error in for loop
Missing semicolon after echo
No error in the code
Infinite loop
Q40
Q40 What is the keyword used to define a function in PHP?
function
def
create
func
Q41
Q41 What is a primary purpose of a function in PHP?
To repeat a block of code multiple times
To stop the execution of a script
To organize and reuse code
To declare variables
Q42
Q42 In PHP, what is a function parameter that is given a default value called?
Mandatory parameter
Optional parameter
Dynamic parameter
Static parameter
Q43
Q43 What is the scope of a variable declared inside a PHP function?
Global
Local
Static
Universal
Q44
Q44 Which of the following statements about PHP anonymous functions is true?
They must have a name
They cannot use external variables
They are a type of PHP class
They can be assigned to a variable or passed as an argument
Q45
Q45 What will be the output of this PHP function call?
function add($x, $y) {
return $x + $y;
}
echo add(2, 3);
5
23
Error
Nothing
Q46
Q46 Given the PHP function:
function isEven($num) {
return $num % 2 == 0;
}
What will isEven(5) return?
true
false
5
null
Q47
Q47 Consider the following PHP function:
function multiply(&$value) {
$value *= 2;
}
$num = 10;
multiply($num);
What will be the value of $num after the function call?
10
20
Error
Null
Q48
Q48 Identify the error in this PHP function definition:
function multiply($x, $y) {
return $x * $y return $x + $y;
}
Multiple return statements
Missing semicolon
Syntax error in return statements
No error in the code
Q49
Q49 Spot the mistake in this PHP function:
function getSum($arr) {
$sum = 0;
foreach($arr as $num) {
$sum += $num;
}
return $sum; } What will getSum([1, 2, 3]) return?
Nothing, there is a syntax error
6
Error due to incorrect parameter type
3
Q50
Q50 In PHP, which function is used to count the number of elements in an array?
count()
get_length()
size()
array_size()
Q51
Q51 What is the purpose of the explode() function in PHP?
To combine array elements into a string
To split a string into an array
To search for a string in an array
To sort an array
Q52
Q52 In PHP, which function is used to join array elements with a string?
join()
merge()
concat()
array_join()
Q53
Q53 Which of the following is a correct way to declare a multidimensional array in PHP?
$array = array(array(1, 2, 3), array(4, 5, 6));
$array = [array(1, 2, 3), array(4, 5, 6)];
$array = {(1, 2, 3), (4, 5, 6)};
$array = {array(1, 2, 3), array(4, 5, 6)};
Q54
Q54 What will be the output of the following PHP code?
$array = ['a', 'b', 'c']; echo $array[1];
a
b
c
Error
Q55
Q55 Consider this PHP code:
$str = "Hello World";
$array = str_split($str, 3);
print_r($array);
What does print_r($array); output?
Array ( [0] => Hel [1] => lo [2] => Wo [3] => rld )
Array ( [0] => Hello [1] => World )
Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => W [7] => o [8] => r [9] => l [10] => d )
Error
Q56
Q56 Identify the issue in this PHP code:
$str = 'Hello'; echo $str[10];
Trying to access an undefined index
Syntax error
No error, it will print 'Hello'
It will print a space
Q57
Q57 Find the error in the following PHP code:
$arr = array("one", "two", "three");
foreach ($ar as $val) {
echo $val;
}
Typo in the variable name inside foreach
Syntax error in array declaration
No error in the code
Error in echo statement
Q58
Q58 What keyword is used to declare a class in PHP?
class
object
new
struct
Q59
Q59 What is the purpose of the __construct() method in a PHP class?
To configure a server
To create an object from the class
To initialize an object's properties
To delete an object
Q60
Q60 In PHP, which keyword is used to inherit a class from another class?
extends
inherits
uses
implements

