Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

PHP MCQ Set 1

1. How many methods does the DateTime class have?
a) 8
b) 9
c) 10
d) 11

View Answer

Answer: b [Reason:] The DateTime class has nine methods, all of which are public.

2. How many constants does the DateTime class have?
a) 8
b) 9
c) 10
d) 11

View Answer

Answer: d [Reason:] The DateTime class has 11 constants, no static properties or methods.

3. Which method is simply an object-oriented version of date()?
a) DateTime::format()
b) DateTime::modify()
c) DateTime::setTime()
d) DateTime::setDate()

View Answer

Answer: a [Reason:] The format() method is simply an object-oriented version of date(). It takes $dateFormat as an argument. $dateFormat is a string consisting of the same date formatting characters accepted by the procedural date() function.

4. Which of the following is the right way to use the DateTime class?
a) $date = get_Class(DateTime);
b) $date = class DateTime;
c) $date = new DateTime();
d) $date = new class DateTime();

View Answer

Answer: c [Reason:] The way you use the DateTime class is like any other class: instantiate an object, and store it in a variable.

5. What will be the output of the following PHP code if date is 24/02/2008?

  1.     <?php
  2.     $date = new DateTime();
  3.     echo $date->format('l,F,js,Y')
  4.     ?>

a) Sunday, February 24th 2008
b) Sunday, 02 24 2008
c) Sunday, 24 02 2008
d) Sunday, 24th February 2008

View Answer

Answer: a [Reason:] The format() method displays the date in same way as standard date function().

6. Which of the following statements can be used to set the time zone in individual scripts?
a) date_set_timezone(‘Europe/London’);
b) date_default_timezone_set(‘Europe/London’);
c) date_set_default_timezone(‘Europe/London’);
d) date_default_timezone(‘Europe/London’);

View Answer

Answer: b [Reason:] You can also use ini_set(‘date.timezone’, ‘Europe/London’);.

7. Among the four PHP DateTimeZone classes given below how many are static?
i) listAbbreviations()
ii) getName()
iii) getOffset()
iv) listIdentifiers()
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] listAbbreviations() and listIdentifiers() are static methods.

8. Among the four PHP DateTimeZone classes given below how many are nonstatic?
i) _construct()
ii) getName()
iii) getOffset()
iv) getTransitions()
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: d [Reason:] All of the given methods are non static.

9. Which of the following statements can be used to add two months to the existing date?
a) $date->modify(‘+2 months’);
b) $date = modify(‘+2 months’);
c) $date = modify(‘2+ months’);
d) $date->modify(‘2+ months’);

View Answer

Answer: a [Reason:] To change the date stored by a DateTime object after it has been created, you use DateTime::modify() with a natural language expression.

10. Which method enables you to calculate whether daylight saving time is in force at a specific date and time?
a) getOffset()
b) getTranitions()
c) ISODate()
d) savingTime()

View Answer

Answer: b [Reason:] This outputs a multidimensional array listing past and future changes to the offset from UTC for a DateTimeZone object.

PHP MCQ Set 2

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

  1. <?php
  2. $x = 10;
  3. $y = 20;
  4. if ($x > $y + $y != 3)
  5.     print "hi" ;
  6. else
  7.     print "how are u";
  8. ?>

a) how are u
b) hi
c) error
d) no output

View Answer

Answer: b [Reason:] Expression evaluates to true.

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

  1. <?php
  2. $x = 10;
  3. $y = 20;
  4. if ($x > $y && 1||1)
  5.     print "hi" ;
  6. else
  7.     print "how are u";
  8. ?>

a) how are u
b) hi
c) error
d) no output

View Answer

Answer: b [Reason:] Expression evaluates to true.

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

  1. <?php
  2. $x = 10;
  3. $y = 20;
  4. if ($x > $y && 1||1)
  5.     print "hi" ;
  6. else
  7.     print "how are u";
  8. ?>

a) how are u
b) hi
c) error
d) no output

View Answer

Answer: b [Reason:] Expression evaluates to true.

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

  1. <?php
  2. if (-100)
  3.     print "hi" ;
  4. else
  5.     print "how are u";
  6. ?>

a) how are u
b) hi
c) error
d) no output

View Answer

Answer: b [Reason:] Expression evaluates to true.

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

  1. <?php
  2. if (0.1)
  3.     print "hi" ;
  4. else
  5.     print "how are u";
  6. ?>

a) how are u
b) hi
c) error
d) no output

View Answer

Answer: b [Reason:] Expression evaluates to true.

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

  1. <?php
  2. if (0.0)
  3.     print "hi" ;
  4. else
  5.     print "how are u";
  6. ?>

a) how are u
b) hi
c) error
d) no output

View Answer

Answer: a [Reason:] Expression evaluates to false.

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

  1. <?php
  2. if (print "0")
  3.     print "hi" ;
  4. else
  5.     print "how are u";
  6. ?>

a) 0how are u
b) 0hi
c) hi
d) how are u

View Answer

Answer: b [Reason:] Expression evaluates to true as print returns 1.

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

  1. <?php
  2. $x = 1;
  3. if ($x == 2)
  4.     print "hi" ;
  5. else if($x = 2)
  6.     print $x;
  7. else
  8.     print "how are u";
  9. ?>

a) error
b) 2
c) hi
d) how are u

View Answer

Answer: b [Reason:] Enters if else as first condition is false and thus x is set to 2.

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

  1. <?php
  2. $x = 1;
  3. if ($x = $x&0)
  4.     print $x ;
  5. else
  6.     print "how are u";
  7. ?>

a) 0
b) 1
c) error
d) how are u

View Answer

Answer: d [Reason:] x&0 is 0,thus evaluated to false.

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

  1. <?php
  2. $x = 1;
  3. if ($x = $x&0)
  4.     print $x ;
  5. else
  6.     print "how are u";
  7. ?>

a) 0
b) 1
c) error
d) how are u

View Answer

Answer: d [Reason:] x&0 is 0,thus evaluated to false.

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

  1. <?php
  2. $x = 1;
  3. if ($x = $x&0)
  4.     print $x;
  5. else
  6.     break;
  7. ?>

a) 0
b) 1
c) error
d) no output

View Answer

Answer: c [Reason:] break is not defined for a if else ladder.

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

  1. <?php
  2. $a = 100;
  3. if ($a > 10)
  4.     printf("M.S. Dhoni");
  5. else if ($a > 20)
  6.     printf("M.E.K Hussey");
  7. else if($a > 30)
  8.     printf("A.B. de villiers");
  9. ?>

a) M.S.Dhoni
b) M.E.K.Hussey
c) M.S.Dhoni
M.E.K.Hussey
A.B.de villiers
d) No output

View Answer

Answer: a [Reason:] In if else if one condition is satisfied then no other condition is checked.

PHP MCQ Set 3

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

  1. <?php
  2. one = 1;
  3. two = 2;
  4. three = 3;
  5. four = 4;
  6. echo "one / two + three / four";
  7. ?>

a) 0.75
b) 0.05
c) 1.25
d) Error

View Answer

Answer: d [Reason:] Variables should start with a $ symbol, since one, two, three, four don’t begin with $ symbol we’ll get an error.

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

  1. <?php
  2. $on$e = 1;
  3. $tw$o = 2;
  4. $thre$e = 3;
  5. $fou$r = 4;
  6. echo "$on$e / $tw$o + $thre$e / $fou$r"; 
  7. ?>

a) 0.75
b) 0.05
c) 1.25
d) Error

View Answer

Answer: d [Reason:] You can not use the $ in between the variable name.

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

  1. <?php
  2. $on_e = 1;
  3. $tw_o = 2;
  4. $thre_e = 3;
  5. $fou_r = 4;
  6. echo $on_e / $tw_o + $thre_e / $fou_r; 
  7. ?>

a) 0.75
b) 0.05
c) 1.25
d) Error

View Answer

Answer: c [Reason:] You can use _ in a variable name.

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

  1. <?php
  2. $On_e = 1;
  3. $tw_o = 2;
  4. $thre_e = 3;
  5. $fou_r = 4;
  6. echo $on_e / $tw_o + $thre_e / $fou_r;
  7. ?>

a) 0.75
b) 0.05
c) 1.25
d) Error

View Answer

Answer: a [Reason:] Since the variable initialised is $On_e and the variable in the echo statement is $on_e the echo statement treats $on_e as 0;

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

  1. <?php
  2. echo $red;
  3. ?>

a) 0
b) Nothing
c) True
d) Error

View Answer

Answer: b [Reason:] There will no output returned as the variable $red does not hold any value.

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

  1. <?php
  2. $four4 = 4;
  3. $three3 = 3;
  4. $two2 = 2;
  5. echo $four4 + $three3 / $two2 - 1;
  6. ?>

a) 4.5
b) 7
c) 3.5
d) Error

View Answer

Answer: a [Reason:] You can use numbers in a variable name.

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

  1. <?php
  2. $4four = 4;
  3. $3three = 3;
  4. $2two = 2;
  5. echo $4four + $3three / $2two - 1;
  6. ?>

a) 4.5
b) 7
c) 3.5
d) Error

View Answer

Answer: d [Reason:] A variable name can not start with a numeric value.

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

  1. <?php
  2. int $one = 1;
  3. echo "$one";
  4. ?>

a) 0
b) 1
c) $one
d) Error

View Answer

Answer: d [Reason:] Unlike other programming languages there are no data types in PHP.

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

  1. <?php
  2. var $one = 1;
  3. var $two = 2;
  4. echo $one / $two * $one / $two * $two;
  5. ?>

a) 1
b) 0
c) 0.5
d) Error

View Answer

Answer: d [Reason:] You can not use var before a variable name.

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

  1. <?php
  2. $hello = "Hello World";
  3. $bye = "Bye";
  4. echo $hello;"$bye";
  5. ?>

a) Hello World
b) Bye
c) Hello worldBye
d) Error

View Answer

Answer: a [Reason:] Since there is a semi-colon in between $hello and $bye, the line ends at $hello. However $bye would have printed if a echo was present before “$bye”.

PHP MCQ Set 4

1. ___ are used in class diagrams to describe the way in which specific elements should be used.
a) Attributes
b) Constraints
c) Constants
d) Class Names

View Answer

Answer: b [Reason:] The {abstract} syntax is an example of a constraint. There is no special structure for the text between the braces; it should simply provide a short clarification of any conditions that may apply to the element.

2. Which one of the following is displayed below the class name in the class diagrams?
a) Functions
b) Methods
c) Attributes
d) Constraints

View Answer

Answer: c [Reason:] Attributes describe a class’s properties. Attributes are listed in the section directly beneath the class name.

3. + is the visibility code for?
a) Public
b) Private
c) Protected
d) Friendly

View Answer

Answer: a [Reason:] The visibility symbol is followed by the name of the attribute.

4. Which relationship is illustrated by a line that begins with an unfilled diamond?
a) Composition
b) Abstraction
c) Aggregation
d) Inheritance

View Answer

Answer: c [Reason:] In the case of aggregation, the contained objects are a core part of the container, but they can also be contained by other objects at the same time.

5. If the diamond is filled it depicts which relationship?
a) Strong Aggregation
b) Composition
c) Abstraction
d) Inheritance

View Answer

Answer: b [Reason:] In composition, the contained object can be referenced by its container only. It should be deleted when the container is deleted.

6. Which one of the following statements is true about sequence diagrams?
a) A sequence diagram is class based
b) A sequence diagram presents the participants of a system from right to left
c) The vertical broken lines represent the lifetime of the class in the system
d) A sequence diagram is object based

View Answer

Answer: d [Reason:] A sequence diagram is object based rather than class based. It is used to model a process in a system step by step.

7. A bidirectional relationship in class diagrams is described by________
a) double-headed arrow
b) visibility symbols
c) single-headed arrow
d) double diamond

View Answer

Answer: a [Reason:] A unidirectional association has single-headed arrow.

8. # is the visibility code for?
a) Private
b) Friendly
c) Protected
d) Static

View Answer

Answer: c [Reason:] Available to the current class and its subclasses only.

9. Which one of the following is displayed in the third section of the class diagram?
a) Operations
b) Inheritance
c) Abstraction
d) Coupling

View Answer

Answer: a [Reason:] Operations describe methods, or more properly, they describe the calls that can be made on an instance of a class.

10. Inheritance in class diagrams is depicted by________
a) single-headed empty arrow
b) single-headed filled arrow
c) double-headed empty arrow
d) double-headed filled arrow

View Answer

Answer: a [Reason:] The UML describes the inheritance relationship as generalization. This relationship is signified by a line leading from the subclass to its parent. The line is tipped with an empty closed arrow.

PHP MCQ Set 5

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

  1. <?php
  2. echo "Hello world </br> I am learning PHP";
  3. ?>

a) Hello world
b) Hello world I am learning PHP
c) Hello world
I am learning PHP
d) Error

View Answer

Answer: c [Reason:] The break tag is used as break line.

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

  1. <?php
  2. echo "Hello world <strong>I am learning PHP</strong>"
  3. ?>

a) Hello world
b) Hello world I am learning PHP
c) Hello world
I am learning PHP
d) Error

View Answer

Answer: b [Reason:] None.

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

  1. <?php
  2. echo "This", "was", "a", "bad", "idea";
  3. ?>

a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error

View Answer

Answer: c [Reason:] In an echo statement the comma operator is used to join strings.

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

  1. <?php
  2. echo "This"."was"."a"."bad"."idea";
  3. ?>

a) This, was, a, bad, idea
b) This was a bad idea
c) Thiswasabadidea
d) Error

View Answer

Answer: c [Reason:] In an echo statement the dot operator is used to join strings.

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

  1. <?php
  2. echo "This","was"|"a","bad"."idea";
  3. ?>

a) Thiswasabadidea
b) Thiswasbadidea
c) Thiswas a badidea
d) Thiswas abadidea

View Answer

Answer: b [Reason:] You can use only comma and dot operator to join starings, other characters do not have the same function.

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

  1. <?php
  2. $one = "Hello";
  3. $two = "World";
  4. echo $one, $two;
  5. ?>

a) Hello World
b) Hello
c) World
d) HelloWorld

View Answer

Answer: d [Reason:] Echo can print two variables which are seperated by a comma.

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

  1. <?php
  2. $one = "Hello";
  3. $two = "World";
  4. echo "$one$two";
  5. ?>

a) HelloWorld
b) $one$two
c) Hello
d) Error

View Answer

Answer: a [Reason:] Even though both the variables are inside the double-quotes, the value of the variable is substituted and then printed to the screen.

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

  1. <?php
  2. $one = "Hello";
  3. $two = "World";
  4. echo "$one"+"$two";
  5. ?>

a) HelloWorld
b) Hello+World
c) 0
d) Error

View Answer

Answer: c [Reason:] In an echo statement you can not use plus sign to join two strings.

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

  1. <?php
  2. echo "This is <i>India</i>";
  3. ?>

a) This is India
b) This is India
c) This is
d) Error

View Answer

Answer: b [Reason:] None.

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

  1. <?php
  2. $cars = array("Volvo", "BMW", "Toyota");
  3. echo "My car is a {$cars[0]}";
  4. ?>

a) My car is a Volvo
b) My car is a BMW
c) My car is a Toyota
d) Error

View Answer

Answer: a [Reason:] In the echo statement the {$cars[0]} is replaced by the 1st element in cars that is Volvo.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com