Q.30 Which of the following is a correct PHP tag?
A. <?php ?>
B. <php>
C. <? ?>
D. <% %>
Answer. A
Q.31 Consider this PHP code:
$str = “Hello World”;
$array = str_split($str, 3);
print_r($array);
What does print_r($array); output?
A. Array ( [0] => Hel [1] => lo [2] => Wo [3] => rld )
B. Array ( [0] => Hello [1] => World )
C. Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => W [7] => o [8] => r [9] => l [10] => d )
D. Error
Answer. A
Q.32 What will be the output of the following PHP code?
$array = [‘a’, ‘b’, ‘c’]; echo $array[1];
A. a
B. b
C. c
D. Error
Answer. B
Q. 33 Which of the following is a correct way to declare a multidimensional array in PHP?
A. $array = array(array(1, 2, 3), array(4, 5, 6));
B. $array = [array(1, 2, 3), array(4, 5, 6)];
C. $array = {(1, 2, 3), (4, 5, 6)};
D. $array = {array(1, 2, 3), array(4, 5, 6)};
Answer. A
Q.34 In PHP, which function is used to join array elements with a string?
A. join()
B. merge()
C. concat()
D. array_join()
Answer. A
Q.35 What is the purpose of the explode() function in PHP?
A. To combine array elements into a string
B. To split a string into an array
C. To search for a string in an array
D. To sort an array
Answer. A
Q.36 In PHP, which function is used to count the number of elements in an array?
A. count()
B. get_length()
C. size()
D. array_size()
Answer. A
Q.37 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?
A. Nothing, there is a syntax error
B. 6
C. Error due to incorrect parameter type
D. 3
Answer. A
Q.38 Identify the error in this PHP function definition:
function multiply($x, $y) {
return $x * $y return $x + $y;
}
A. Multiple return statements
B. Missing semicolon
C. Syntax error in return statements
D. No error in the code
Answer. C
Q.39 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?
A. 10
B. 20
C.Error
D. Null
Answer. B
Q.40 Given the PHP function:
function isEven($num) {
return $num % 2 == 0;
}
What will isEven(5) return?
A. true
B. false
C. 5
D. null
Answer. B
Q.41 What will be the output of this PHP function call?
function add($x, $y) {
return $x + $y;
}
echo add(2, 3);
A. 5
B. 23
C. Error
D. Nothing
Answer. A
Q.42 Which of the following statements about PHP anonymous functions is true?
A. They must have a name
B. They cannot use external variables
C. They are a type of PHP class
D. They can be assigned to a variable or passed as an argument
Answer. D
Q.43 What is the scope of a variable declared inside a PHP function?
A. Global
B. Local
C. Static
D. Universal
Answer. B
Q.44 In PHP, what is a function parameter that is given a default value called?
A. Mandatory parameter
B. Optional parameter
C. Dynamic parameter
D. Static parameter
Answer. B
Q.45 What is a primary purpose of a function in PHP?
A. To repeat a block of code multiple times
B. To stop the execution of a script
C. To organize and reuse code
D. To declare variables
Answer. C