Pre-Test What Is PHP?:: F. Assessment
Pre-Test What Is PHP?:: F. Assessment
Pre-Test What Is PHP?:: F. Assessment
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:
Direction: Complete the line PHP statements given below. Write your answer on the space
provided.
1
echo “Hello World!”;
?>
<?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;
$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;
$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) {
3
echo "Hello";
break;
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
Description:
Write a program to check student grade based on the marks using if-else statement.
Conditions:
4
● If marks between 96 to 97, grade will be 1.25.
ANSWER HERE:
<?php
$mark = 75;
$grade;
switch ($mark){
$grade = 1;
break;
$grade = 1.25;
break;
5
case $mark >= 92:
$grade = 1.5;
break;
$grade = 1.75;
break;
$grade = 2;
break;
$grade = 2.25;
break;
$grade = 2.75;
break;
$grade = 3;
break;
$grade = 5;
break;
6
}
echo $grade;
?>
Requirement # 2
Description:
Write a program to arrange the order of a series of numbers based on the given order
Conditions:
ANSWER HERE:
<?php
$order = "d";
if ($order == "a"){
sort ($series);
7
}elseif ($order == "d"){
rsort ($series);
?>