Learn PHP MCQs

Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.

Which operator is used to concatenate two strings in PHP?

1) .

2) +

3) &

4) ||

Answer : Option 1

How can you generate a random number in PHP?

1) rand()

2) random()

3) generate_random()

4) random_number()

Answer : Option 1

Which of the following is a superglobal variable in PHP?

1) $_POST

2) $_GET

3) $_SESSION

4) All of the above

Answer : Option 4

How do you check if a variable is an array in PHP?

1) is_array()

2) array()

3) isarray()

4) check_array()

Answer : Option 1

Which function is used to return the current date and time in PHP?

1) date()

2) datetime()

3) getdate()

4) now()

Answer : Option 1

How do you convert a string to an array in PHP?

1) explode()

2) split()

3) str_split()

4) array()

Answer : Option 1

Which of the following is a correct way to declare a PHP variable?

1) $var = "value";

2) var = "value";

3) var $var = "value";

4) $var: "value";

Answer : Option 1

How can you include a file in PHP, but suppress errors?

1) @include "file.php";

2) include_once "file.php";

3) require "file.php";

4) require_once "file.php";

Answer : Option 1

Which of the following function is used to redirect a user to a different page in PHP?

1) header()

2) redirect()

3) location()

4) redirect_to()

Answer : Option 1

Which function is used to check for the presence of a key in an array in PHP?

1) array_key_exists()

2) key_exists()

3) in_array()

4) exists()

Answer : Option 1