Create New Post

PHP MCQs - 6

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

    • A) Converts a string to lowercase
    • B) Searches for files matching a specified pattern
    • C) Parses a URL
    • D) Encodes data using MIME base64

    Answer: B) Searches for files matching a specified pattern

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

    $str = "Hello World";
    echo strpos($str, "World");
    
    • A) 0
    • B) 5
    • C) 6
    • D) -1

    Answer: B) 6

  3. Which of the following PHP functions is used to retrieve the current timestamp?

    • A) now()
    • B) timestamp()
    • C) time()
    • D) current_time()

    Answer: C) time()

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

    • A) Converts a string to uppercase
    • B) Truncates a string to a specified length
    • C) Reverses the characters in a string
    • D) Searches for a substring within a string

    Answer: B) Truncates a string to a specified length

  5. Which of the following is used to start a session in PHP?

    • A) start_session()
    • B) session_start()
    • C) new_session()
    • D) begin_session()

    Answer: B) session_start()
     

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

     $arr = [1, 2, 3, 4, 5];
    echo array_sum($arr);

    • A) 15
    • B) 10
    • C) 5
    • D) Error

    Answer: A) 15

  7. Which of the following PHP functions is used to send an email?

    • A) mail()
    • B) send_mail()
    • C) email_send()
    • D) smtp_send()

    Answer: A) mail()

  8. What does the implode() function in PHP do?

    • A) Splits a string into an array
    • B) Joins elements of an array into a string
    • C) Reverses the characters in a string
    • D) Removes whitespace from the beginning and end of a string

    Answer: B) Joins elements of an array into a string

  9. What is the purpose of the json_encode() function in PHP?

    • A) Converts a JSON string into an object
    • B) Encodes a PHP variable into a JSON string
    • C) Decodes a JSON string into an array
    • D) Removes whitespace from the beginning and end of a string

    Answer: B) Encodes a PHP variable into a JSON string

  10. Which of the following PHP functions is used to redirect the user to another URL?

    • A) redirect()
    • B) header()
    • C) location()
    • D) goto()

    Answer: B) header()

Comments

Leave a Reply

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

87463