menu

PHP Syntax


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

include "filename";

require "filename";

include_once "filename";

all of the above


2. 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


3. 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


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

.

+

-

*


5. What is the correct syntax to access an element in an array in PHP?

$array[element];

$array[element]

array[element];

array[element]


6. 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 {}


7. Which of the following is used to define a constant in PHP?

define('Constant_name', 'value');

constant Constant_name = value;

Constant_name = value;

all of the above


8. What is the correct syntax to create an array in PHP?

$array = [1, 2, 3];

$array = array(1, 2, 3);

$array = {1, 2, 3};

$array = (1, 2, 3);


9. Which of the following is used to create an object of a class in PHP?

Class_name = new Class();

new Object = Class_name();

new Class_name();

Object = new Class_name;


10. 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