Create New Post

PHP MCQs - 2

  1. What is the result of the expression 10 % 3 in PHP?

    • A) 3
    • B) 1
    • C) 0
    • D) 2

    Answer: B) 1

  2. Which of the following is used to concatenate two strings in PHP?

    • A) .
    • B) +
    • C) &
    • D) ,

    Answer: A) .

  3. What does the strlen() function in PHP do?

    • A) Returns the number of elements in an array
    • B) Returns the length of a string
    • C) Returns the last element of an array
    • D) Returns the position of a substring in a string

    Answer: B) Returns the length of a string

  4. How do you include one PHP file within another PHP file?

    • A) include "filename.php";
    • B) require "filename.php";
    • C) include_once "filename.php";
    • D) All of the above

    Answer: D) All of the above

  5. What is the output of the code below?

     $x = 5;
    echo $x++; // Post-increment
    
    • A) 5
    • B) 6
    • C) 4
    • D) Error

    Answer: A) 5

  6. Which of the following is used to create a constant in PHP?

    • A) define()
    • B) const()
    • C) constant()
    • D) var()

    Answer: A) define()

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

    • A) Adds one or more elements to the beginning of an array
    • B) Removes the last element from an array
    • C) Adds one or more elements to the end of an array
    • D) Checks if a value exists in an array

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

  8. Which of the following is used to access the value of a specific element in an associative array?

    • A) $array[index]
    • B) $array->index
    • C) $array['index']
    • D) Both A and C

    Answer: C) $array['index']

  9. What does the session_start() function do in PHP?

    • A) Ends the current session
    • B) Starts a new session or resumes the existing one
    • C) Destroys all data registered to a session
    • D) Resets the session ID

    Answer: B) Starts a new session or resumes the existing one

  10. What is the correct way to check if a file exists in PHP?

    • A) file_exists()
    • B) exists_file()
    • C) is_file()
    • D) check_file_exists()

    Answer: A) file_exists()

Comments

Leave a Reply

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

76954