1. Which of the following is a valid PHP conditional statement?
2. What is the correct syntax for an if-else statement in PHP?
3. Which PHP statement is used to test multiple conditions?
4. How do you correctly use a switch statement in PHP?
5. Which of the following is a correct while loop syntax in PHP?
6. What will the following loop output?
for ($i = 1; $i <= 3; $i++) {
echo $i;
}
7. Which loop is guaranteed to execute at least once?
8. How do you define a function in PHP?
9. How do you return a value from a function in PHP?
10. What is the scope of a variable defined inside a function?
11. How do you pass parameters to a function in PHP?
12. What keyword is used to make a variable global inside a function?
13. What does the continue statement do in a loop?
14. What does the break statement do in PHP loops?
15. What will the following function output?
function test($x = 5) {
return $x * 2;
}
echo test(10);
16. What is the correct syntax for a foreach loop?
17. What happens if a function does not have a return statement?
18. What is the default parameter value in PHP functions?
19. Can a function call itself in PHP?
20. Which keyword defines a static variable inside a function?
21. What will be the output of the following code?
function example() {
static $x = 0;
$x++;
echo $x;
}
example();
example();
22. How do you include an external PHP file?
23. What happens if a required file is missing?
24. What is the output of strlen("PHP")?
25. How do you create a function with variable arguments in PHP?
