PHP Quizs Question & Answers Basics – 3

Q 1. Who is the father of PHP?
A. Rasmus Lerdorf
B. Willam Makepiece
C. Drek Kolkevi
D. List Barely

Show Answer Answer:-A. Rasmus Lerdorf
Explanation PHP was originally created by Rasmus Lerdorf in 1994

Q 2. Which of the conditional statements is/are supported by PHP?

i) if statements
ii) if-else statements
iii) if-elseif statements
iv) switch statements

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

Show Answer Answer:-D. i), ii), iii) and iv)
Explanation All are conditional statements supported by PHP as all are used to evaluate different conditions during a program and take decisions based on whether these conditions evaluate to true of false.

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

  1. <?php
  2. $team = “arsenal”;
  3. switch ($team) {
  4. case “manu”:
  5. echo “I love man u”;
  6. case “arsenal”:
  7. echo “I love arsenal”;
  8. case “manc”:
  9. echo “I love manc”; }
  10. ?>

A. I love arsenal
B. Error
C. I love arsenalI love manc
D. I love arsenalI love mancI love manu

Show Answer Answer:-C. I love arsenalI love manc
Explanation If a break statement isn’t present, all subsequent case blocks will execute until a break statement is located.

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

  1. <?php
  2. $user = array(“Ashley”, “Bale”, “Shrek”, “Blank”);
  3. for ($x=0; $x < count($user); $x++) {
  4. if ($user[$x] == “Shrek”) continue;
  5. printf ($user[$x]);
  6. }
  7. ?>

A. AshleyBale
B. AshleyBaleBlank
C. ShrekBlank
D. Shrek

Show Answer Answer:-B. AshleyBaleBlank
Explanation The continue statement causes execution of the current loop iteration to end and commence at the beginning of the next iteration.

Q 5. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?
A. 12
B. 1
C. Error
D. 5

Show Answer Answer:-D. 5
Explanation ?: is known as ternary operator. If condition is true then the part just after the ? is executed else the part after : .

Q 6. What will be the value of $a and $b after the function call in the following PHP code?

  1. <?php
  2. function doSomething( &$arg ) {
  3. $return = $arg;
  4. $arg += 1;
  5. return $return;
  6. }
  7. $a = 3;
  8. $b = doSomething( $a );
  9. ?>

A. a is 3 and b is 4
B. a is 4 and b is 3
C. Both are 3
D. Both are 4

Show Answer Answer:-B. a is 4 and b is 3
Explanation $a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.

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

  1. <?php
  2. $a = 5;
  3. $b = 5;
  4. echo ($a === $b);
  5. ?>

A. 5 === 5
B. Error
C. 1
D. False

Show Answer Answer:-C. 1
Explanation === operator returns 1 if $a and $b are equivalent and $a and $b have the same type.

Q 8. Which of the looping statements is/are supported by PHP?

i) for loop
ii) while loop
iii) do-while loop
iv) foreach loop

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

Show Answer Answer:-C. i), ii), iii) and iv)
Explanation All are supported looping statements in PHP as they can repeat the same block of code a given number of times, or until a certain condition is met.

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

  1. <?php
  2. $num = 10;
  3. echo ‘What is her age? \n She is $num years old’;
  4. ?>

A. What is her age? \n She is $num years old
B. What is her age?She is $num years old

C. What is her age? She is 10 years old
D. What is her age?She is 10 years old

Show Answer Answer:-A. What is her age? \n She is $num years old
Explanation When a string is enclosed within single quotes both variables and escape sequences will not be interpreted when the string is parsed.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page