Php programming language MCQ : Function and String : Link1

Php programming language MCQ : Function and String : Link1

Function and String MCQ

       Are you worried about the answers to PHP programming-Function and String-Default parameters, Variable function, Anonymous function questions? We have arranged the Show Answer button under the each question. Candidates can click on it to know the right option among the given alternatives. Furthermore, the applicants can check our web portal @ www.totalmcq.com to take part in more MCQ on various subject. Wish, the given information about the Function and String MCQ will helpful to the advance and can learn the various types of questions and answers.


Q.1. Which of the following are valid function names?
i) function()
ii) abc()
iii) .function()
iv) $function()

A. Only i)                                                              B. Only ii)
C. i) and ii)                                                        D. iii) and iv)

Q.2. What will be the output of the following PHP code?

 <?php \\
    \:\:\:\:function\:\:\: x() \\
     \{ \\
         function \:\:\: y() \\
                 \{ \\
                     echo\:\: ' I\:\: am\:\: x\:'; \\
                         \} \\
                   echo \:\:'I \:\:am\:\: y\:';\\
                \:\:\: \} \\
             x();\\
x();\\
?>













A. I am x                                             B. I am yI am x
C. Error                                           D. I am x Error

Q.3. How to define a function in PHP?

A. function {function body}
B. functionName(parameters) {function body}
C. function functionName(parameters) {function body}
D. data type functionName(parameters) {function body}

Q.4. What will be the output of the following PHP code?

 <?php \\
    \:\:\:\:function\:\:\: x() \\
     \{ \\
         function \:\:\: y() \\
                 \{ \\
                     echo\:\: ' I\:\: am\:\: x\:'; \\
                         \} \\
                   echo \:\:'I \:\:am\:\: y\:';\\
                \:\:\: \} \\
             y();\\
x();\\
?>












A. I am x                                      B. I am yI am x
C. Error                                       D. I am x Error

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

 <?php \\
    \:\:\:\:$option2 = "\:bye\:" \\
     function \:\:foo() \\
     \{ \\
         function \:\: foo($option1) \\
                 \{ \\
                     echo\:\:$option1; \\
echo\:\:$option2; \\
                         \} \\
                   foo("hello");\\
?>












A.hellobye                                              B. hello
C. Error                                               D. hellobyebye

Q.6. How many types of functions are available in php?

A. 5                                                              B. 3
C. 2                                                                               D. 4

Q.7. Which of the following is not a built-in function in php ?

A. fopen()                                                                          B. print_r()
C. gettype()                                                                       D. fclosed()

Q.8. Why should we use functions?

A. Reusability
B. Easier error detection
C. Easily maintained
D. All of the above

Q.9. A function name always begins with the keyword -------

A. fun                                                  B. def
C. function                                                  D. None of the above

Q.10. A function name cannot start with a -----.

A. alphabet                                                                                B. underscore
C. number                                                                             D. Both C and B