Home / CSE / PHP - CS :: Functions in PHP

CSE :: PHP - CS

  1. What will be the output of the following PHP code?

    <?php

    echo ucwords("i love my country");

    ?>

  2. A.

     I love my country

    B.

     i love my Country

    C.

     I love my Country

    D.

     I Love My Country


  3. What will be the output of the following PHP code?

    <?php

    echo lcfirst("welcome to India");

    ?>

  4. A.

     welcome to India

    B.

     welcome to india

    C.

     Welcome to India

    D.

     Welcome to india


  5. What will be the output of the following PHP code?

    <?php

    function calc($price, $tax="")

    {

    $total = $price + ($price * $tax);

    echo "$total";

    }

    calc(42);

    ?>

  6. A.

     Error

    B.

     0

    C.

     42

    D.

     84


  7. What will be the output of the following PHP code?

    <?php

    function a()

    {

    function b()

    {

    echo 'I am b';

    }

    echo 'I am a';

    }

    a();

    a();

    ?>

  8. A.

     I am b

    B.

     I am bI am a

    C.

     Error

    D.

     I am a Error


  9. What will be the output of the following PHP code?

    <?php

    function a()

    {

    function b()

    {

    echo 'I am b';

    }

    echo 'I am a';

    }

    b();

    a();

    ?>

  10. A.

     I am b

    B.

     I am bI am a

    C.

     Error

    D.

     I am a Error


  11. What will be the output of the following PHP code?

    <?php

    $op2 = "blabla";

    function foo($op1)

    {

    echo $op1;

    echo $op2;

    }

    foo("hello");

    ?>

  12. A.

     helloblabla

    B.

     error

    C.

     hello

    D.

     helloblablablabla


  13. What will be the output of the following PHP code?

    <?php

    function foo($msg)

    {

    echo "$msg";

    }

    $var1 = "foo";

    $var1("will this work");

    ?>

  14. A.

     error

    B.

     $msg

    C.

     0

    D.

     will this work


  15. Which one of the following is the right way of defining a function in PHP?

  16. A.

     function { function body }

    B.

     data type functionName(parameters) { function body }

    C.

     functionName(parameters) { function body }

    D.

     function fumctionName(parameters) { function body }


  17. Type Hinting was introduced in which version of PHP?

  18. A.

     PHP 4

    B.

     PHP 5

    C.

     PHP 5.3

    D.

     PHP 6


  19. What will happen in this function call?

    <?php

    function calc($price, $tax)

    {

    $total = $price + $tax;

    }

    $pricetag = 15;

    $taxtag = 3;

    calc($pricetag, $taxtag);

    ?>

  20. A.

     Call By Value

    B.

     Call By Reference

    C.

     Default Argument Value

    D.

     Type Hinting