menu

PHP Syntax


1. Which of the following is used to execute a block of code only if a condition is true in PHP?

if statement

switch statement

for loop

while loop


2. Which of the following is used to redirect the user to another page in PHP?

header('Location: new_page.php');

redirect('new_page.php');

location('new_page.php');

none of the above


3. What is the correct syntax to declare a variable in PHP?

$variable_name;

var variable_name;

$variable_name =;

variable_name;


4. What is the correct syntax to include a file in PHP?

include "filename";

require "filename";

include_once "filename";

all of the above


5. Which of the following is used to define a class in PHP?

define class Class_name {}

Class Class_name {}

new Class Class_name {}

class Class_name {}


6. Which of the following is used to check if a variable is set in PHP?

isset($variable)

$variable is set

$variable set

all of the above


7. Which of the following is used to loop through the values of an array in PHP?

for loop

while loop

foreach loop

do-while loop


8. Which of the following is used to select one of several blocks of code to be executed in PHP?

if statement

switch statement

for loop

while loop


9. Which of the following is used to check if a variable is null in PHP?

is_null($variable)

$variable == null

$variable === null

all of the above


10. Which of the following is used to concatenate two strings in PHP?

.

+

-

*