Functions(Php ) Questions and Answers

Question 1. Which one of the following is the right way of defining a function in PHP?
  1.    function { function body }
  2.    data type functionName(parameters) { function body }
  3.    functionName(parameters) { function body }
  4.    function fumctionName(parameters) { function body }
Explanation:-
Answer: Option D. -> function fumctionName(parameters) { function body }

Question 2. What will happen in this function call?
  1.    Call By Value
  2.    Call By Reference
  3.    Default Argument Value
  4.    Type Hinting
Explanation:-
Answer: Option A. -> Call By Value
When you pass an argument in the above manner or say we pass 15 and 3 directly, it is called passing by value or call by value.

Question 3. Type Hinting was introduced in which version of PHP?
  1.    PHP 4
  2.    PHP 5
  3.    PHP 5.3
  4.    PHP 6
Explanation:-
Answer: Option B. -> PHP 5
Type hinting gives you the ability to force parameters to be objects of certain class or to be arrays. PHP 5 introduced this feature.

Question 4. What will be the output of the following PHP code?
  1.    Error
  2.    0
  3.    42
  4.    84
Explanation:-
Answer: Option C. -> 42
You can designate certain arguments as optional by placing them at the end of the list and assigning them a default value of nothing.

Question 5. Which of the following are valid function names?
1. function()
2. €()
3. .function()
4. $function()
  1.    Only 2
  2.    None of the mentioned
  3.    All of the mentioned
  4.    3 and 4
Explanation:-
Answer: Option A. -> Only 2
Except a) others are invalid names. According to the specified regular expression ([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*), a function name like this one is valid.

Question 6. What will be the output of the following PHP code ?
  1.    o world!
  2.    Hello world!
  3.    111
  4.    No Output
Explanation:-
Answer: Option A. -> o world!
111 is the ASCII value of o.

Question 7. Phpinfo() will display about?
1. OS version information
2. PHP installation
3. Variables
4. HTTP headers
  1.    Option 1
  2.    Option 2
  3.    Option 3
  4.    Option 4
  5.    All the Above
Explanation:-
Answer: Option E. -> All the Above

Question 8.  . . . . . converts the keys of an array into values and the values into keys.
  1.    array_flips()
  2.    array_transpose()
  3.    array_trans()
  4.    array_flip()
Explanation:-
Answer: Option D. -> array_flip()

Question 9. Above usleep() function pauses PHP for .
usleep(1000000);
  1.    1 second
  2.    1 microseconds
  3.    10 seconds
  4.    100 microseconds
Explanation:-
Answer: Option A. -> 1 second

Question 10. Output will be:
$array = array(0, 1, 2);
$array = array_pad($array, -6, ‘NEW’);
  1.    Array ( [1] => NEW [2] => NEW [3] => NEW [4] => 0 [5] => 1 [6] => 2 )
  2.    Array ( [-1] => NEW [-2] => NEW [-3] => NEW [-4] => 0 [-5] => 1 [-6] => 2 )
  3.    Array ( [0] => NEW [-1] => NEW [-2] => NEW [-3] => 0 [-4] => 1 [-5] => 2 )
  4.    Array ( [0] => NEW [1] => NEW [2] => NEW [3] => 0 [4] => 1 [5] => 2 )
Explanation:-
Answer: Option D. -> Array ( [0] => NEW [1] => NEW [2] => NEW [3] => 0 [4] => 1 [5] => 2 )