On PHP | More Q&A Click Here
# | Question | Options | Answer |
---|---|---|---|
1 | What does PHP stand for? | Hypertext Preprocessor | |
2 | Which symbol is used to prepend variables in PHP? | $ | |
3 | Which of the following is the correct way to declare a variable in PHP? | $variableName = value | |
4 | Which of the following functions is used to output text in PHP? | All of the above | |
5 | How do you create an array in PHP? | $array = array("value1", "value2", "value3") | |
6 | Which of the following is used to get the length of a string in PHP? | strlen($string) | |
7 | Which superglobal variable is used to collect form data sent with both GET and POST methods? | $_REQUEST | |
8 | How do you define a constant in PHP? | define("CONSTANT_NAME", "value") | |
9 | Which of the following is used to check if a variable is set and is not NULL in PHP? | isset() | |
10 | Which of the following is used to connect to a MySQL database in PHP? | mysqli_connect() | |
11 | Which function is used to start a session in PHP? | session_start() | |
12 | Which function is used to start a session in PHP? | session_start() | |
13 | Which of the following is used to terminate the execution of a script in PHP? | exit | |
14 | Which of the following is correct about PHP variables? | Variables do not need to be declared before use. | |
15 | Which function is used to start output buffering in PHP? | ob_start() | |
16 | Which superglobal variable holds information about headers, paths, and script locations? | $_SERVER | |
17 | How do you remove an element from an array in PHP? | unset($array[index]) | |
18 | Which PHP function is used to destroy a session? | D) session_destroy() | |
19 | Which PHP function is used to find the length of a string? | B) strlen() | |
20 | What function is used to search for the position of the first occurrence of a substring in a string? | A) strpos() | |
21 | Which PHP function is used to replace all occurrences of a search string with a replacement string? | B) str_replace() | |
22 | What function converts a string to all lowercase letters in PHP? | D) strtolower() | |
23 | To convert a string to all uppercase letters in PHP, you use which function? | D) strtoupper() | |
24 | Which PHP function is used to reverse a string? | C) strrev() | |
25 | To compare two strings in PHP, which function is used? | C) strcmp() | |
26 | Which function is used to repeat a string a specified number of times in PHP? | B) str_repeat() | |
27 | What PHP function is used to split a string into an array by a specified delimiter? | C) explode() | |
28 | To join array elements into a single string using a delimiter, which function do you use in PHP? | B) implode() | |
29 | Which PHP function is used to format a Unix timestamp into a human-readable date? | D) date() | |
30 | What function generates a unique ID in PHP? | C) uniqid() | |
31 | Which PHP function is used to sort an array in ascending order? | C) sort() | |
32 | To sort an array in descending order in PHP, you use which function? | A) rsort() | |
33 | To sort an associative array in descending order by value in PHP, which function do you use? | A) arsort() | |
34 | To sort an associative array in descending order by keys in PHP, which function is used? | A) krsort() | |
35 | Which PHP function shuffles the elements of an array randomly? | A) shuffle() | |
36 | What function is used to count all elements in an array in PHP? | A) count() | |
37 | Which PHP function merges two or more arrays into a single array? | A) array_merge() | |
38 | Which function is used to count all elements in an array? | D) count() | |
39 | How do you add an element to the end of an array? | C) array_push() | |
40 | Which function is used to remove the last element of an array? | A) array_pop() | |
41 | What function adds one or more elements to the beginning of an array? | A) array_unshift() | |
42 | Which function is used to remove the first element of an array? | B) array_shift() | |
43 | How do you merge two or more arrays in PHP? | B) array_merge() | |
44 | Which function is used to check if a value exists in an array? | B) in_array() | |
45 | How do you get all the keys of an array? | A) array_keys() | |
46 | Which function returns all the values of an array? | A) array_values() | |
47 | How do you sort an array in ascending order? | B) sort() | |
48 | Which function sorts an array in descending order? | A) rsort() | |
49 | What function returns the number of elements in an array? | C) count() | |
50 | How do you extract a slice of an array? | A) array_slice() | |
51 | Which function removes a portion of an array and replaces it with something else? | B) array_splice() | |
52 | What function searches an array for a given value and returns the key? | A) array_search() | |
53 | How do you apply a user function to every member of an array? | C) array_walk() | |
54 | Which function returns an array with elements in reverse order? | A) array_reverse() | |
55 | How do you remove duplicate values from an array? | A) array_unique() | |
56 | Which function calculates the sum of values in an array? | A) array_sum() | |
57 | How do you determine if a variable is an array? | A) is_array() | |
58 | What keyword is used to define a class in PHP? | B) class | |
59 | What is the visibility keyword to make a property or method accessible only within the class itself? | C) private | |
60 | How do you define a constant in a class? | A) const NAME = value | |
61 | What keyword is used to inherit from a parent class? | B) extends | |
62 | Which keyword is used to define a method that must be implemented by all subclasses of an abstract class? | C) abstract | |
63 | What keyword is used to implement an interface in a class? | C) implements | |
64 | Can a class implement multiple interfaces in PHP? | Yes | |
65 | What keyword prevents a class from being inherited? | B) final | |
66 | Which visibility keyword allows a property or method to be accessed from within the class and its subclasses? | B) protected | |
67 | What is the keyword to make a property or method belong to the class rather than an instance? | A) static | |
68 | Which magic method is called when an object is serialized? | C) __sleep() | |
69 | What method is called when an object is destroyed? | C) __destruct() | |
70 | What is the visibility keyword to make a property or method accessible from outside the class? | A) public | |
71 | Which keyword is used to define a trait in PHP? | A) trait | |
72 | How do you use a trait in a class? | A) use TraitName |