PHP

PHP

Functions 2 has 53 Questions
What will be the output of the following PHP code?
  1.     <?php
  2.     function calc($price, $tax="")
  3.     {
  4.         $total = $price + ($price * $tax);
  5.         echo "$total"; 
  6.     }
  7.     calc(42);    
  8.     ?>

Error
0
42
84
What will be the output of the following PHP code?
  1.     <?php
  2.     function a()
  3.     {
  4.         function b()
  5.         {
  6.             echo 'I am b';
  7.         }
  8.         echo 'I am a';
  9.     }
  10.     a();
  11.     a();
  12.     ?>

I am b
I am bI am a
Error
I am a Error
What will be the output of the following PHP code?
  1.     <?php
  2.     function a()  
  3.     {
  4.         function b()
  5.         {
  6.             echo 'I am b';
  7.         }
  8.         echo 'I am a';
  9.     }
  10.     b();
  11.     a();
  12.     ?>

I am b
I am bI am a
Error.
I am a Error
What will be the output of the following PHP code?
  1.     <?php
  2.     $op2 = "blabla";
  3.     function foo($op1)
  4.     {
  5.         echo $op1;
  6.         echo $op2;
  7.     }
  8.     foo("hello");
  9.     ?>

helloblabla
Error
hello
helloblablablabla
hat will be the output of the following PHP code?
  1.     <?php
  2.         function foo($msg)
  3.         {
  4.             echo "$msg";
  5.         }
  6.         $var1 = "foo";
  7.         $var1("will this work");
  8.     ?>

Error.
$msg
0
will this work
What will be the output of the following PHP code?
  1.     <?php
  2.        echo "chr(52)";
  3.     ?>

1
2
3
4
What will be the output of the following PHP code?
  1.     <?php
  2.         echo ord ("hi");
  3.     ?>

106
103
104
209
What will be the output of the following PHP code?
  1.     <?php
  2.         define("GREETING1","Hello you! How are you today?");
  3.         define("GREETING2","Hello you! How are you today?");
  4.         define("GREETING3","Hello you! How are you today?");
  5.         echo defined("GREETING");
  6.      ?>

1
0
3
4
What will be the output of the following PHP code?
  1.    <?php
  2.        define("GREETING","Hello you! How are you today?");
  3.        echo constant("GREETING");
  4.    ?>

Hello you! How are you today?
GREETING
GREETING, Hello you! How are you today?
"GREETING"?,"?Hello you! How are you today?"?
What will be the output of the following PHP code?
  1. <?php
  2.     function sum($num1, $num2)
  3.     {
  4.         $total = $num1 + $num2;
  5.         echo "chr($total)"; 
  6.     }
  7.     $var1 = "sum";
  8.     $var1(5, 44);    
  9. ?>

Error
49
1
sum
What will be the output of the following PHP code?
  1. <?php
  2.     function sum($num1, $num2)
  3.     {
  4.         $total = $num1 + $num2;
  5.         echo "cos($total)"; 
  6.     }
  7.     sum(5,-5);    
  8. ?>

0
1
0.5
-0.5
What will be the output of the following PHP code?
  1. <?php
  2.     function b()
  3.     {
  4.         echo "b is executed";
  5.     }
  6.     function a()
  7.     {
  8.         b();
  9.         echo "a is executed";
  10.         b();
  11.     }
  12.     a();
  13.   ?>

b is executedb is executedb is executed
b is executeda is executed
a is executed
b is executeda is executedb is executed
What will be the output of the following PHP code?
  1. <?php
  2. function sum($x, $y)
  3. {
  4.     $z = $x + $y;
  5.     return $z;
  6. }
  7. echo "5 + 10 = " . sum(7,13) . "
    "
    ;
  8. echo "7 + 13 = " . sum(2,4) . "
    "
    ;
  9. echo "2 + 4 = " . sum(5,10);
  10. ?>

5 + 10 = 15 2 + 4 = 6 7 + 13 = 20
7 + 13 = 20 5 + 10 = 15 2 + 4 = 6
5 + 10 = 15 7 + 13 = 20 2 + 4 = 6
5 + 10 = 20 7 + 13 = 6 2 + 4 = 15
What will be the output of the following PHP code?
  1. <?php
  2. function addFive($num)
  3. {
  4.     $num += 5;
  5. }
  6. function addSix(&$num)
  7. {
  8.     $num += 6;
  9. }
  10. $orignum = 10;
  11. addFive( &$orignum );
  12. echo "Original Value is $orignum
    "
    ;
  13. addSix( $orignum );
  14. echo "Original Value is $orignum
    "
    ;
  15. ?>

Original Value is 15 Original Value is 21
Original Value is 15 Original Value is 21
Original Value is 15 Original Value is 15
None Of The Above
What will be the output of the following PHP code?
  1. <?php
  2. function addFunction($num1, $num2)
  3. {
  4.     $sum = $num1 + $num2;
  5.     return $sum;
  6. }
  7. $return_value = addFunction(10, 20);
  8. echo "Returned value from the function : $return_value"
  9. ?>

Returned value from the function : $return_value
Error
Returned value from the function : 30
Returned value from the function :
What will be the output of the following PHP code?
  1. <?php
  2. function sayHello()
  3. {
  4.    echo "HelloWorld
    "
    ;
  5. }
  6. $function_holder = "sayHello";
  7. $function_holder();
  8. ?>

No Output
Error
sayHello
HelloWorld
What will be the output of the following PHP code?
  1. <?php
  2. function do($myString)
  3. {
  4.     echo strpos($myString, "donkey",0);
  5. }
  6. do("The donkey looks like a horse.");
  7. ?>

4
5
2
None Of The Above
What will be the output of the following PHP code?
  1. <?php
  2. function one()
  3. {
  4.     define("const","I am awesome!");
  5.     echo constant("const");
  6. }
  7. one();
  8. ?>

I am awesome!!
const
const, I am awesome!!
"const"?,"?I am awesome!"?
What will be the output of the following PHP code?
  1. <?php
  2.     $title = "O'malley wins the heavyweight championship!";
  3.     echo ucwords($title);
  4. ?>

O'Malley Wins The Heavyweight Championship!
O'malley Wins The Heavyweight Championship!
O'Malley wins the heavyweight championship!
o'malley wins the heavyweight championship!
What will be the output of the following PHP code?
  1. <?php
  2.     echo str_pad("Salad", 5)." is good.";
  3. ?>

SaladSaladSaladSaladSalad is good
is good SaladSaladSaladSaladSalad
is good Salad
Salad is good
What will be the output of the following PHP code?
  1. <?php
  2.     $str = "Hello World"
  3.     echo wordwrap($str,5,"<br>\n");    
  4. ?>

Hello World

Hello

World

Hell

wo

rld

World
What will be the output of the following PHP code?
  1. <?php
  2.     echo ucwords("i love my country");
  3. ?>

I love my country
i love my Country
I love my Country
I Love My Country
What will be the output of the following PHP code?
  1. <?php
  2.     echo lcfirst("welcome to Astiwz");
  3. ?>

welcome to Astiwz
welcome to india
Welcome to Astiwz
Welcome to india
What will be the output of the following PHP code?
  1. <?php
  2.     echo hex2bin("48656c6c6f20576f726c6421");
  3. ?>

Hello World!
welcome to india
This is PHP!
MCQ questons
What will be the output of the following PHP code?
  1. <?php
  2.     echo strtr("Hilla Warld","ia","eo");
  3. ?>

Hilla Warld
Hello World
ia
eo
What will be the output of the following PHP code?
  1. <?php
  2.     echo stripos("I love php, I love php too!","PHP");
  3. ?>

3
7
8
10
What will be the output of the following PHP code?
  1.  <?php
  2.     $str = addslashes('What does "yolo" mean?');
  3.     echo($str); 
  4. ?>

What does /"?yolo/"? mean?
What does \\"?yolo\\"? mean?
What does \"?yolo\"? mean?
\What does \"?yolo\"? mean?\
What will be the output of the following PHP code ?
  1. <?php
  2.     function A1($x)
  3.     {
  4.         switch($x)
  5.         {
  6.         case 1: 
  7.             //this statement is the same as if($x == 1)
  8.             echo 'Case 1 was executed.';
  9.             break;
  10.         case 2: 
  11.             //this statement is the same as if($x == 2)
  12.             echo 'Case 2 was executed.';
  13.             break;
  14.         case 3: 
  15.             //this statement is the same as if($x == 3)
  16.             echo 'Case 3 was executed.';
  17.             break;
  18.         case 4: 
  19.             //this statement is the same as if($x == 4)
  20.             echo 'Case 4 was executed.';
  21.             break;
  22.         default: 
  23.             //this statement is the same as if $x does not equal the other conditions
  24.             echo 'Default was executed.';
  25.             break;
  26. ?
  27.         }
  28.     }
  29.     A1(9);
  30. ?>

Case 1 was executed.
Case 2 was executed.
Default was executed.
Case 4 was executed.
What will be the output of the following PHP code ?
  1. <?php
  2.     function uppercase($string)
  3.     {
  4.         echo ucwords($string);
  5.     }
  6.     $wow = "uppercase";
  7.     $wow("Time to live king size");
  8. ?>

TIME TO LIVE KING SIZE
Time to live king size
uppercase
Time To Live King Size
What will be the output of the following PHP code ?
  1. <?php
  2.     function TV($string)
  3.     {
  4.         echo "my favourite TV show is ".$string;
  5.         function b()
  6.         {
  7.             echo " I am here to spoil this code";
  8.         }
  9.     }
  10.     b();
  11. ?>

I am here to spoil this code
Error
my favourite TV show isI am here to spoil this code
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2.     function TV($string)
  3.     {
  4.         echo "my favourite TV show is ".$string;
  5.         function b()
  6.         {
  7.             echo " I am here to spoil this code";
  8.         }
  9.     }
  10.     function b()
  11.     {
  12.         echo " I am here to spoil this code";
  13.     }
  14.     b();
  15. ?>

I am here to spoil this code
Error
my favourite TV show isI am here to spoil this code
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2.     function TV($string)
  3.     {
  4.         echo "my favourite TV show is ".$string;
  5.         function b()
  6.         {
  7.             echo " I am here to spoil this code";
  8.         }
  9.     }
  10.     function b()
  11.     {
  12.         echo " I am here to spoil this code";
  13.     }
  14.     b();
  15.     TV("Sherlock");
  16. ?>

I am here to spoil this code
Error
my favourite TV show isI am here to spoil this code
None Of The Above
What will be the output of the following PHP code ?
  1. <?php
  2.     function TV($string)
  3.     {
  4.         echo "my favourite TV show is ".$string;
  5.         function b()
  6.         {
  7.             echo " I am here to spoil this code";
  8.         }
  9.     }
  10.     TV("Sherlock");
  11.     b();
  12. ?>

I am here to spoil this code
Error
my favourite TV show is SherlockI am here ro spoil this code
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2.     function calc($num1, $num2)
  3.     {
  4.         $total = $num1 * $num2; 
  5.     }
  6.     $result = calc(42, 0);
  7.     echo $result;    
  8. ?>

Error
0
42
84
What will be the output of the following PHP code ?
  1. <?php
  2.     $var = 10;
  3.     function one()
  4.     {
  5.         echo $var;
  6.     }
  7.     one();
  8. ?>

Error
10
No Output
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2.     function mine($m)
  3.     {
  4.         if ($m < 0)
  5.             echo "less than 0";
  6.         if ($ >= 0)
  7.             echo "Not True";
  8.     }
  9.     mine(0);
  10. ?>

Less Than 0
Not True
No Output
None of the above
What will be the output of the following PHP code ?
  1.  <?php
  2. $x = 75;
  3. $y = 25; 
  4. function addition()
  5. {
  6.     $GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
  7. }
  8. addition();
  9. echo $z;
  10. ?>

100
error
75
25
What will be the output of the following PHP code ?
  1. <?php
  2. function _func()
  3. {
  4.     echo "Hello World";
  5. }
  6. _func();
  7. ?>

Hello World
No Output
ERROR
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2. function 2myfunc()
  3. {
  4.     echo "Hello World";
  5. }
  6. 2myfunc();
  7. ?>

Hello World
No Output
ERROR
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2. function mine($num)
  3. {
  4.     $num = 2 + $num;
  5. echo $num;
  6. }
  7. mine(3);
  8. ?>

3
$num
5
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2. function test($int)
  3. {
  4.     if ($int == 1)
  5.         echo "This Works";
  6.     if ($int == 2)
  7.         echo "This Too Seems To Work";
  8. }
  9. test(1);
  10. TEST(2);
  11. ?>

This Works
This Too Seems To Work
This WorksThis Too Seems To Work
ERROR
What will be the output of the following PHP code ?
  1. <?php
  2. function test($int)
  3. {
  4.     if ($int == 1)
  5.         echo "This Works";
  6.     if ($int == 2)
  7.         echo "This Too Seems To Work";
  8. }
  9. test(1);
  10. TEST(2);
  11. ?>

This Works
This Too Seems To Work
This WorksThis Too Seems To Work
ERROR
What will be the output of the following PHP code ?
  1. <?php
  2. function mine($num)
  3. {
  4.     $num = 2 + $num;
  5.     echo "$num";
  6. }
  7. mine(3);
  8. ?>

3
$num
5
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2. function one($string)
  3. {
  4.     echo "I am ". $String;
  5. }
  6. one("Batman");
  7. ?>

I am Batman
I am
Batman
ERROR
What will be the output of the following PHP code ?
  1. <?php
  2. function colour()
  3. { 
  4.     $colors = array("red", "green", "blue", "yellow"); 
  5.     foreach ($colors as $value)
  6.     {
  7.         echo "$value ";
  8.     }
  9. }
  10. colour();
  11. ?>

red green blue yellow
green blue yellow red
red blue yellow green
red green yellow blue
What will be the output of the following PHP code ?
  1. <?php
  2. function addFunction($num1, $num2)
  3. {
  4.     $sum = $num1 + $num2;
  5.     return $sum;
  6. }
  7. $return_value = addFunction(10, 20);
  8. echo "Returned value from the function : " .$return_value
  9. ?>

Returned value from the function : $return_value
Error
Returned value from the function : 30
Returned value from the function :
What will be the output of the following PHP code ?
  1. <?php
  2. function time($string)
  3. {
  4.     echo strtr("Towe Pa55", "ow5", $string);
  5. }
  6. time("ims");
  7. ?>

Time Pa55
Towe Pa55
Towe Pass
Time Pass
What will be the output of the following PHP code ?
  1. <?php
  2. function constant()
  3. {
  4.     define("GREETING", "Welcome to Narnia");
  5.     echo greeting;
  6. }
  7. ?>

Welcome to Narnia
greeting
GREETING
ERROR
What will be the output of the following PHP code ?
  1. <?php
  2. function constant()
  3. {
  4.     define("GREETING", "Welcome to Narnia",true);
  5.     echo greeting;
  6. }
  7. ?>

Welcome to Narnia
greeting
GREETING
ERROR
What will be the output of the following PHP code ?
  1. <?php
  2. function start($string)
  3. {
  4.     if ($string < 45)
  5.         return 20;
  6.     else
  7.         return 40;
  8. }
  9. $t = start(90);
  10. if ($t < 20)
  11. {
  12.     echo "Have a good day!";
  13. }
  14. else
  15. {
  16.     echo "Have a good night!";
  17. }
  18. ?>

Have a good day!
Have a good night!
ERROR
None of the above
What will be the output of the following PHP code ?
  1. <?php
  2. function case()
  3. {
  4.     ECHO "Hello World!<br>";
  5.     echo "Hello World!<br>";
  6.     EcHo "Hello World!<br>";
  7. }
  8. case();
  9. ?>

Hello World!

Hello World!

Hello World!

Hello World!

Hello World!

Hello World!

None of the above
What will be the output of the following PHP code ?
  1. <?php
  2. function CalAll($x,$y)
  3. {
  4.     echo ($x + $y);
  5.     echo " ";
  6.     echo ($x - $y);
  7.     echo " ";
  8.     echo ($x * $y);
  9.     echo " ";
  10.     echo ($x / $y); 
  11.     echo " ";
  12.     echo ($x % $y);
  13. }
  14. $x = 10; 
  15. $y = 6;
  16. CalcAll(); 
  17. ?>

4    60    1.6666666666667    4    16
16    4    60    1.6666666666667    4
4  16  4  60  1.6666666666667
1.6666666666667    4    16  4  60
What will be the output of the following PHP code ?
  1. <?php
  2. function string()
  3. {
  4.     echo strstr("Hello world!", 111);
  5. }
  6. string();
  7. ?>

o world!
Hello world!
111
No Output