Create New Post

PHP MCQs - 9

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

    
     

    $x = 5;
    echo ++$x * 2;

    • A) 12
    • B) 14
    • C) 11
    • D) 10

    Answer: B) 14

  2. Which of the following PHP functions is used to convert a string to lowercase?

    • A) to_lower()
    • B) strtolower()
    • C) lower_case()
    • D) case_lower()

    Answer: B) strtolower()

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

    • A) Merges two or more arrays into a single array
    • B) Sorts an array in ascending order
    • C) Reverses the order of elements in an array
    • D) Removes duplicate values from an array

    Answer: A) Merges two or more arrays into a single array

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

    $str = "PHP is a popular scripting language.";
    echo str_word_count($str);
    
    • A) 6
    • B) 5
    • C) 7
    • D) 8

    Answer: B) 5

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

    • A) is_object()
    • B) object_check()
    • C) check_object()
    • D) obj_check()

    Answer: A) is_object()

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

    $num = 123;
    echo strval($num);
    
    • A) 123
    • B) "123"
    • C) '123'
    • D) Error

    Answer: A) 123

  7. Which of the following PHP functions is used to round a floating-point number to the nearest integer?

    • A) ceil()
    • B) floor()
    • C) round()
    • D) abs()

    Answer: C) round()

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

    • A) Splits a string into an array
    • B) Joins elements of an array into a string
    • C) Reverses the order of elements in an array
    • 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 output of the following code snippet?

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

    Answer: C) -1

  10. Which of the following PHP functions is used to replace a substring within a string?

    • A) str_replace()
    • B) substr_replace()
    • C) replace_str()
    • D) str_modify()

    Answer: A) str_replace()

Comments

Leave a Reply

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

43646