-
Which of the following PHP functions is used to determine whether a variable is empty?
- A) empty()
- B) isset()
- C) is_empty()
- D) null()
Answer: A) empty()
-
What is the purpose of the
serialize()
function in PHP?- A) Converts an array into a JSON string
- B) Converts an object into a string representation
- C) Encrypts a string
- D) Converts special characters to HTML entities
Answer: B) Converts an object into a string representation
-
Which of the following is used to retrieve the value of a specific cookie in PHP?
- A) $_COOKIE['cookie_name']
- B) $_SESSION['cookie_name']
- C) $_GET['cookie_name']
- D) $_POST['cookie_name']
Answer: A) $_COOKIE['cookie_name']
-
What is the purpose of the
explode()
function in PHP?- A) Combines two or more strings into one
- B) Splits a string into an array based on a delimiter
- C) Removes whitespace from the beginning and end of a string
- D) Returns the position of a substring in a string
Answer: B) Splits a string into an array based on a delimiter
-
What is the output of the following code snippet?
$x = 10; $y = 5; echo $x > $y ? "Greater" : "Smaller";
- A) Greater
- B) Smaller
- C) Error
- D) None of the above
Answer: A) Greater
-
Which of the following is used to read the contents of a file into an array in PHP?
- A) file_get_contents()
- B) fopen()
- C) file()
- D) readfile()
Answer: C) file()
-
What does the
shuffle()
function do in PHP?- A) Sorts an array in ascending order
- B) Sorts an array in descending order
- C) Reverses the order of elements in an array
- D) Randomly shuffles the elements of an array
Answer: D) Randomly shuffles the elements of an array
-
Which of the following is used to execute a PHP script from the command line?
- A) php_execute()
- B) execute_php()
- C) php -f filename.php
- D) run_php_script()
Answer: C) php -f filename.php
-
What is the purpose of the
header()
function in PHP?- A) Sends HTTP headers to the client
- B) Includes an external PHP file
- C) Defines a constant
- D) Prints output to the browser
Answer: A) Sends HTTP headers to the client
-
Which of the following is used to remove duplicate values from an array in PHP?
- A) array_unique()
- B) array_diff()
- C) array_merge()
- D) array_combine()
Answer: A) array_unique()
Comments