Pet Inforamtion: '.$name2 .' is '. $age2 . ' years old. '. ' Its owner is '.$owner2 . ', its favorite toy is '. $fav_toy2 .' and it is ' . $NeuOrSprayed2;
//declaring variable x and y to hold values 5 and 6
//Declaring a variable in php
$x = 5;
$y = 6;
$Sum = $x+ $y;
echo '
The sum is '.$Sum;
$Difference = $y - $x;
echo '
The difference is '.$Difference;
$Product = $x * $y;
echo '
The product is '.$Product;
$Modulus = $y / $x;
echo '
The modulus is '.$Modulus;
//incrementing a
$a = 0;
$a = ++$x;
echo '
The increment is '.$a;
//decrementing b
$b = 0;
$b = --$y;
echo '
The decrement is '.$b;
//when the code echo($num++) is executed, the number will stay at 4 because it's a post-increment meaning the program will return $num THEN increment $num by one
//when the code echo(++$num) is executed, the number will increment by 1 because it's a pre-increment meaning the program will automatically add one to 4, the program will return a value of 5.
//Activity 2
/*
using if-statements, test and display if the pet from activity 1 is:
*7 yrs old
*older than 7 and has an owner named ada
*named terror or has slipper as favourite toy
*/
if($age1 == 7){
echo '
'."Age is 7";
} else {
echo '
'."No, Age is not 7";
}
if($age1 >= 7 && $owner1=="Ada"){
echo '
'."Age is older than 7 whose owner is Ada";
} else {
echo '
'."No, Age is not older than 7 and its owner is not Ada";
}
if($name1 == "Terror" || $fav_toy1=="Slipper"){
echo '
'."Name is terror or favourite toy is slipper";
} else {
echo '
'."Name is not terror nor favourite toy is slipper";
}
//using the if-else decision structure to display the day of the week based on the current character stored in day
$day = 'U' ;//. 'M' . 'T' . 'W' . 'R' . 'F' . 'S';
if($day == 'U') {
echo '
'."Sunday"; //I helped! ty!
}
if($day == 'M') {
echo '
'. "Monday";
}
if($day == 'T') {
echo '
'."Tuesday";
}
if($day == 'W') {
echo '
'."Wednesday";
}
if($day == 'R') {
echo '
'."Thursday";
}
if($day == 'F') {
echo '
'."Friday";
}
if($day == 'S') {
echo '
'."Saturday";
}
//using the ternary operator to assess if x is less than y.
if($x < $y) {
echo '
'."X is smaller than y";
} else {
echo '
'."X is not smaller than y";
}
if($x >= $y) {
echo '
'."X is greater than or equals to y";
} else {
echo '
'."X is less than y";
}
//Activity 3
//displaying odd numbers between 0 and 20 in descending order
echo '
' . "Odd numbers between 0 and 20: ";
for($i=20-1; $i>=0; $i=$i-2) {
echo '
' . ($i . "
");
}
//displaying the 7-times table
$count=0;
$num=7;
while ($count!=13){
$multiple= $num * $count;
echo '
' . $num. 'x'. $count.'='.($multiple . "
");
$count = $count + 1;
}
//creating the associative array
$course_ranking['Internet Tech'] = 7.5;
$course_ranking['Info Proj. Management'] = 4;
$course_ranking['Comp. Network, Arc & Protocol'] = 5;
$course_ranking['Fundamentals of Research'] = 6;
//displaying the array contents
echo '
' . "Course Ranking for Internet Technology is " . $course_ranking['Internet Tech'];
echo '
' . "Course Ranking for Information Project Management is " . $course_ranking['Info Proj. Management'];
echo '
' . "Course Ranking for Computer Network Architecture & Protocol is " . $course_ranking['Comp. Network, Arc & Protocol'];
echo '
' . "Course Ranking for Fundamentals of Research is " . $course_ranking['Fundamentals of Research'] . '
';
//sorting the array
$course_ranking = array('Internet Tech'=>7.5, 'Info Proj. Management'=>4, 'Comp. Network, Arc & Protocol'=>5, 'Fundamentals of Research'=>6);
asort($course_ranking);
foreach($course_ranking as $w => $w_value) {
echo '
' . "Course=" . $w . ", Ranking=" . $w_value;
echo "
";
}
?>