Create New Post

PHP MCQs - 7

  1. What is the purpose of the session_destroy() function in PHP?

    • A) Starts a new session
    • B) Destroys all session variables
    • C) Removes a specific session variable
    • D) Checks if a session variable exists

    Answer: B) Destroys all session variables

  2. What is the output of the following code snippet?

    echo "Hello" . 2 + 3 . "World";
    
    
    • A) Hello5World
    • B) Hello23World
    • C) 5Hello3World
    • D) Error

    Answer: B) Hello23World

  3. Which of the following PHP functions is used to retrieve information about a file?

    • A) fileinfo()
    • B) fileinfo_stat()
    • C) file_info()
    • D) file_stat()

    Answer: B) fileinfo_stat()

  4. What is the purpose of the array_push() function in PHP?

    • A) Removes the last element from an array
    • B) Adds an element to the beginning of an array
    • C) Removes the first element from an array
    • D) Adds one or more elements to the end of an array

    Answer: D) Adds one or more elements to the end of an array

  5. What is the correct way to define a constant in PHP?

    • A) define_constant()
    • B) constant_define()
    • C) set_constant()
    • D) define()

    Answer: D) define()

  6. Which of the following is used to execute a block of code repeatedly as long as a condition is true in PHP?

    • A) for loop
    • B) foreach loop
    • C) while loop
    • D) do-while loop

    Answer: C) while loop

  7. What does the is_numeric() function do in PHP?

    • A) Checks if a variable is a number or numeric string
    • B) Converts a string to a number
    • C) Checks if a variable is an integer
    • D) Checks if a variable is empty

    Answer: A) Checks if a variable is a number or numeric string

  8. What is the output of the following code snippet?

    $x = "5";
    $y = "10";
    echo $x + $y;
     
    • A) 15
    • B) 510
    • C) 5
    • D) Error

    Answer: A) 15

  9. Which of the following PHP functions is used to count the number of elements in an array?

    • A) array_length()
    • B) count()
    • C) array_count()
    • D) sizeof()

    Answer: B) count()

  10. What does the array_reverse() 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) Removes duplicate values from an array

    Answer: C) Reverses the order of elements in an array

Comments

Leave a Reply

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

98539