Create New Post

PHP MCQs - 5

  1. 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()

  2. 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

  3. 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']

  4. 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

  5. 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

  6. 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()

  7. 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

  8. 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

  9. 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

  10. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

30107