Learn PHP MCQs

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

Which function is used to get the IP address of the client in PHP?

1) $_SERVER["REMOTE_ADDR"]

2) $_SERVER["HTTP_HOST"]

3) $_SERVER["SERVER_NAME"]

4) $_SERVER["CLIENT_IP"]

Answer : Option 1

Which function is used to delete an array element in PHP?

1) unset()

2) delete()

3) remove()

4) array_delete()

Answer : Option 1

Which of the following is used to compare two strings in PHP?

1) strcmp()

2) str_compare()

3) compare()

4) strcmpr()

Answer : Option 1

How do you create an associative array with multiple elements in PHP?

1) $arr = array("key1" => "value1", "key2" => "value2");

2) $arr = ["key1" => "value1", "key2" => "value2"];

3) $arr = assocarray("key1", "value1", "key2", "value2");

4) Both A and B

Answer : Option 4

Which of the following is used to find the type of a variable in PHP?

1) gettype()

2) typeof()

3) vartype()

4) getvar()

Answer : Option 1

Which function is used to generate a one-time password in PHP?

1) password_hash()

2) hash_password()

3) generate_otp()

4) one_time_password()

Answer : Option 1

Which of the following is used to encode a string in Base64 in PHP?

1) base64_encode()

2) encode_base64()

3) base_encode()

4) b64encode()

Answer : Option 1

How do you set a time limit for script execution in PHP?

1) set_time_limit()

2) time_limit()

3) execution_time()

4) set_execution_time()

Answer : Option 1

Which function is used to format a number with grouped thousands in PHP?

1) number_format()

2) format_number()

3) num_format()

4) format_num()

Answer : Option 1

Which function is used to return the ASCII value of a character in PHP?

1) ord()

2) chr()

3) ascii()

4) getascii()

Answer : Option 1