Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following functions can be used to return the current Unix timestamp?
1) time()
2) timestamp()
3) current_time()
4) unix_time()
Answer : Option 1
How do you check if an array is associative in PHP?
1) array_keys($array) !== range(0, count($array) - 1)
2) is_associative()
3) is_array($array) && array_keys($array) === range(0, count($array) - 1)
4) None of the above
Answer : Option 1
What does the `call_user_func()` function do in PHP?
1) Calls a callback function
2) Creates a new function
3) Defines a function
4) None of the above
Answer : Option 1
How do you create a new directory in PHP?
1) mkdir()
2) new_directory()
3) create_dir()
4) dir_create()
Answer : Option 1
What is the purpose of the `isset()` function in PHP?
1) Checks if a variable is set and is not NULL
2) Checks if a variable is empty
3) Checks if a variable is an array
4) None of the above
Answer : Option 1
Which function is used to find the first occurrence of a string inside another string?
1) strpos()
2) strstr()
3) substr()
4) find()
Answer : Option 1
What is the output of `echo "10" == 10;` in PHP?
1) 1
2) True
3) False
4) 0
Answer : Option 1
How do you find the first key of an array in PHP?
1) array_key_first()
2) array_keys()[0]
3) reset()
4) key()
Answer : Option 1
What does the `error_log()` function do in PHP?
1) Sends an error message to a log file
2) Displays an error message
3) Stops script execution on error
4) None of the above
Answer : Option 1
How do you generate a random integer in PHP?
1) rand()
2) generate_random()
3) random_int()
4) integer_random()
Answer : Option 1