PHP Functions Quiz

Last Updated :
Discuss
Comments

Question 1

What keyword is used to declare a function in PHP?

  • A

    function

  • B

    declare

  • C

    def

  • D

    func

Question 2

What is the purpose of the return statement in PHP functions?

  • A

    It stops the execution of the function.

  • B

    It sends a value back to the function caller.

  • C

    It prints the output directly.

  • D

    It defines the function's parameters.


Question 3

Which of the following PHP functions is used to calculate the length of a string?

  • A

    strlen()

  • B

    substr()

  • C

    strpos()

  • D

    explode()

Question 4

How do you pass arguments to a function in PHP?

  • A

    By calling the function with parameters

  • B

    By using the pass() keyword

  • C

    By defining variables inside the function

  • D

    Arguments are not needed in PHP functions

Question 5

What does the array_push() function do in PHP?

  • A

    Removes an element from the beginning of the array

  • B

    Adds an element to the end of the array

  • C

    Sorts the array in ascending order

  • D

    Merges two arrays

Question 6

What is the purpose of anonymous functions in PHP?

  • A

    To call functions recursively

  • B

    To define functions without names, often for passing as arguments

  • C

    To create private functions

  • D

    To define default functions

Question 7

Which PHP function is used to convert a string to a date format?

  • A

    strtotime()

  • B

    date()

  • C

    time()

  • D

    mktime()

Question 8

Which PHP function is used to get the current date or time?

  • A

    time()

  • B

    date()

  • C

    current()

  • D

    getTime()

Question 9

What is the output of the following code?

JavaScript
function add($a, $b) {
    return $a + $b;
}
echo add(5, 3);



  • A

    53

  • B

    8

  • C

    5 + 3

  • D

    Error

Question 10

What is the result of the following PHP code?

JavaScript
function greet($name) {
    return "Hello, " . $name;
}
echo greet("Shubham");


  • A

    Hello, Shubham

  • B

    Hello,

  • C

    Shubham

  • D

    Error

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion