0% found this document useful (0 votes)
6 views

PHP Chapter 2 Assignment

PHP revision questions

Uploaded by

Ogal Peter
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PHP Chapter 2 Assignment

PHP revision questions

Uploaded by

Ogal Peter
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. What do you understand by the term “Case Sensitive Language”?

Case sensitive language distinguishes between uppercase and lowercase letters when
interpreting identifiers like variables, functions, and keywords.

2. How many code declaration blocks can be inserted in a PHP document?


You can insert as many code declaration blocks as needed in a PHP document.

3. Why does the PHP Group recommend that you use standard PHP script
delimiters to write PHP code declaration blocks?
PHP Group recommends using standard PHP script delimiters (<?php…..?>)
because they ensure compatibility across all PHP configurations and
environments.

4. Identify the two types of comments available in PHP and indicate when each
would be used.
 Single-line comment: Using // or #. Used for short, one-line comments.
 Multi-line comment: Using /* ... */. Used for longer comments or when
you need to comment out multiple lines of code.

5. What is difference between the echo and print statement in PHP?


 echo- Does not return a value and can output multiple arguments. It is marginally
faster.
 print- Returns a value of 1 and can only output one argument. It is slightly
slower than echo.
6. Write names list of PHP program structure.
 PHP opening tag: <?php
 Statements and expressions: Written between the PHP tags.
 Comments: Single-line (//, #) and multi-line (/* ... */).
 Control structures: if, else, for, while, etc.
 Closing PHP tag: ?>
Practical Questions
1. Write a simple PHP program to print your BIODATA on the browser screen.
<?php
echo "<h1>BIODATA</h1>";
echo "<p>Name: Greg Ayieko</p>";
echo "<p>Age: 21</p>";
echo "<p>Email: [email protected]</p>";
?>
2. Elaborate the Error(s) in the code below (if any).
<?php
/ This is a comment for PHPprogram
echo "Display first line </br>";
echo "Display second line </br> "
Print "Display third line with print statement ";
?>
 The comment should be prefixed with either // or /* ... */.
 The second echo statement is missing a semicolon (;).
 The print statement has incorrect capitalization and is missing a semicolon after the
closing quotation mark.

2. Write down the correct code of above program.


<?php
// This is a comment for PHP program
echo "Display first line </br>";
echo "Display second line </br>";
print "Display third line with print statement";
?>

3. Mention the output of above code.


Display first line
Display second line
Display third line with print statement

4. Write PHP code to display any text on the browser uses HTML formatting
tags within the echo statements.
<?php
echo "<h1>This is a heading</h1>";
echo "<p>This is a paragraph with <strong>bold text</strong> in it.</p>";
?>
Objective and MCQ’s
1. What do you use to separate multiple argument that are passed to a function …..a
comma(B)
a) A period ( . )
b) A comma ( , )
c) A forward slash ( / )
d) A backward slash ( \ )

2. You create line comments in PHP code by adding _//__ to a line you want to use a
comment. a) ||
b) **
c) /*
d) //
3. Block comments begin with /* and end with ____ */
a) */
b) /*
c) //
d) **

4. Print has a return value of 0 or 1

a) 0 or 1
b) Greater 1
c) Less than 1
d) Not all above
5. The rules for using a programming language are called _syntax______.
a) Protocols
b) Syntax
c) Variables
d) Comments
6. We can use HTML elements in the PHP scripting. You chose corrects code are
following. echo “<h1> Pakistan</h1>”;

a) echo " h1 Pakistan /h ";


b) echo " <h1> Pakistan </h1> ";
c) echo <h1> Pakistan </h1> ";
d) <h1> Pakistan </h1>
7. All PHP statements must be end with a _semicolon______.
a) Semicolon
b) Commas
c) Double quotations
d) Single quotations
8. Combine variables and constants to create new values that are called _expression___.
a) Variables
b) Statement
c) Expression
d) Concatenation
9. PHP keywords or function must be used in ___lower case_______case
a) Upper case
b) Camel case
c) Sentence case
d) Lower case
10 Standard PHP script delimiters <?php?>
a) <? ?>
b) <?php ?>
c) <% %>
d) <script language="php" > … </script>

You might also like