You are on page 1of 8

PRE-TEST

What is php?:
PHP is a general-purpose scripting language geared towards web development. It was originally
created by Danish-Canadian programmer Rasmus Lerdorf in 1994. The PHP reference
implementation is now produced by The PHP Group.
How to install PHP locally?:
To run PHP scripts on any machine(server, computer etc) we need PHP installed on it
1. PHP Parser: To execute PHP scripts, PHP installation is required.
2. Web Server: Because PHP is mostly used to develop websites, hence most of its
implementations come bundled with Apache Web Server, which is required to host the
application developed in PHP over HTTP.
3. Database: Anyone database management system, which is generally MySQL, as PHP comes
with a native support for MySQL
Now, you can install all the 3 services separately yourself, or you can simply download
and install software that automatically installs all the above services.
What are the rules in creating PHP variables? :
Rules for PHP variables:
1. A variable name will always start with a $ sign, followed by the variable name.

2. A variable name should not start with a numeric value. It can either start with an alphabet or
an underscore sign _.

3. A variable name can only contain alphabets, numbers and underscore symbol _.

4. Variable names in PHP are case-sensitive, which means $love is not same as $Love.

F. Assessment:

A. Fill in the blanks:

Direction: Complete the line PHP statements given below. Write your answer on the space
provided.

1. Insert the missing part of the code output “Hello World!”.


<?php

1
echo “Hello World!”;
?>

2. Insert the missing part of the code to validate PHP tags.

<?php ?>
3. Complete the code below to embed PHP with HTML code.

<!DOCTYPE>
<html>
<body>
<?php
$w = “Welcome to PHP Programming”;
____echo____ “<h1> ____$w______ </h1>”;
?>
</body>
</html>
4. Multiply 20 with 5, and output the result.

echo 20 ___*__ 5;

5. Output "Hello World" if $a is greater than $b.

$a = 50;
$b = 10;
If($a > $b ) { echo "Hello

World";

}
6. Output $i as long as $i is less than 10.

$i = 1;

2
while ( $i< 10) {

echo $i;
$i++;
} ($i< 10)
7. Output $i as long as $i is less than 6.

$i = 1;
do {

echo $i;

$i++;

} while ($i< 6;

8. Output "Yes" if $a is equal to $b, otherwise output "No".

$a = 50;
$b = 10;

if ($a == $b) {

echo "Yes";

} else {

echo "No";

}
9. Create a switch statement that will output "Hello" if $color is "red", and "welcome" if
$color is "green".

___switch__ ($color) {

case $color__ == "red":

3
echo "Hello";

break;

_case $color_ == "green":

echo "Welcome";

break;

}
10. Create one variable named x, and one variable named y, then use the echo statement to
output the sum of x and y.

$x = 5;

$y = 7;

echo $x + $y ;

Requirement # 1

Write a program to check student grade based on marks

Description:

Write a program to check student grade based on the marks using if-else statement.

Conditions:

● If marks are 98 or more, grade will be 1.0.

4
● If marks between 96 to 97, grade will be 1.25.

● If marks between 92 to 95, grade will be 1.50.

● If marks between 89 to 91, grade will be 1.75.

● If marks between 86 to 88, grade will be 2.0.

● If marks between 83 to 85, grade will be 2.25.

● If marks between 80 to 82, grade will be 2.75.

● If marks between 75 to 79, grade will be 3.0.

● If marks are less than 74, the grade will be 5.0.

ANSWER HERE:

<?php

$mark = 75;

$grade;

switch ($mark){

case $mark >= 98:

$grade = 1;

break;

case $mark >= 96:

$grade = 1.25;

break;

5
case $mark >= 92:

$grade = 1.5;

break;

case $mark >= 89:

$grade = 1.75;

break;

case $mark >= 86:

$grade = 2;

break;

case $mark >= 83:

$grade = 2.25;

break;

case $mark >= 80:

$grade = 2.75;

break;

case $mark >= 75:

$grade = 3;

break;

case $mark <= 74:

$grade = 5;

break;

6
}

echo $grade;

?>

Requirement # 2

Write a program to arrange the order of a series of numbers.

Description:

Write a program to arrange the order of a series of numbers based on the given order

sequence. Use any statements necessary to resolve the required output.

Conditions:

● If $order is ‘A’, the series of numbers will be arranged in ascending order.

● If $order is ‘D’, the series of numbers will be arranged in descending order.

● Series of numbers are 5,7, 3, 4, 6, 8, 1, 2, 9, 10

ANSWER HERE:

<?php

$order = "d";

$series = array (5,7, 3, 4, 6, 8, 1, 2, 9, 10);

if ($order == "a"){

sort ($series);

7
}elseif ($order == "d"){

rsort ($series);

foreach ($series as $var)

echo "$var \n";

?>

You might also like