Create New Post

PHP MCQs - 10

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

    $x = 10;
    $y = 3;
    echo $x % $y;
     
    • A) 3
    • B) 1
    • C) 0
    • D) 2

    Answer: B) 1

  2. Which of the following PHP functions is used to calculate the square root of a number?

    • A) sqrt()
    • B) square_root()
    • C) root()
    • D) sqr()

    Answer: A) sqrt()

  3. What is the purpose of the array_keys() function in PHP?

    • A) Returns all the values of an array
    • B) Returns all the keys of an array
    • C) Returns the number of elements in an array
    • D) Reverses the order of elements in an array

    Answer: B) Returns all the keys of an array

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

  5. Which of the following PHP functions is used to generate a unique ID?

    • A) uniqid()
    • B) unique_id()
    • C) generate_id()
    • D) random_id()

    Answer: A) uniqid()

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

    $str = "Hello World!";
    echo strtoupper($str);
    
    • A) hello world!
    • B) HELLO WORLD!
    • C) Hello World!
    • D) Error

    Answer: B) HELLO WORLD!

  7. Which of the following PHP functions is used to check if a variable is an array?

    • A) is_array()
    • B) array_check()
    • C) check_array()
    • D) verify_array()

    Answer: A) is_array()

  8. What is the purpose of the array_shift() function in PHP?

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

    Answer: C) Removes the first element from an array

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

    $str = "Hello,World";
    $arr = explode(",", $str);
    print_r($arr);
    
    • A) Hello World
    • B) Hello, World
    • C) Array ( [0] => Hello [1] => World )
    • D) Error

    Answer: C) Array ( [0] => Hello [1] => World )

  10. Which of the following PHP functions is used to generate a random integer?

    - A) random_int()

    - B) rand()
    - C) mt_rand()
    - D) random()

    **Answer: A) random_int()**
     

Comments

Leave a Reply

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

45115