Learn PHP MCQs
Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.
How do you remove the first element from an array in PHP?
1) array_shift()
2) array_unshift()
3) array_pop()
4) array_remove()
Answer : Option 1
Which of the following is a valid PHP constant name?
1) __CLASS__
2) __CONST__
3) __METHOD__
4) __FUNCTION__
Answer : Option 2
Which function is used to open a file in PHP?
1) fopen()
2) fileopen()
3) file_open()
4) openfile()
Answer : Option 1
What does the PHP function str_replace() do?
1) Replaces all occurrences of a search string with a replacement string
2) Finds a string in another string
3) Splits a string into an array
4) Combines two strings
Answer : Option 1
Which of the following is the correct way to create a class in PHP?
1) class MyClass {}
2) create class MyClass {}
3) define MyClass() {}
4) class = MyClass {}
Answer : Option 1
How do you get the last modification time of a file in PHP?
1) filemtime()
2) filetime()
3) lastmodtime()
4) modtime()
Answer : Option 1
Which function is used to delete a file in PHP?
1) unlink()
2) remove()
3) delete()
4) erase()
Answer : Option 1
How do you check if a variable is an array in PHP?
1) is_array()
2) array_check()
3) array_var()
4) is_var_array()
Answer : Option 1
How do you sort an array by values in ascending order?
1) asort()
2) ksort()
3) arsort()
4) sort()
Answer : Option 1
What is the correct way to create an instance of a class in PHP?
1) $obj = new MyClass();
2) $obj = MyClass();
3) $obj = class MyClass();
4) $obj = create MyClass();
Answer : Option 1