Advertisement
thotfrnk

week2.php

Sep 20th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <title>Week Two Collab</title>
  7. </head>
  8. <body>
  9.   <div>
  10.   <?php
  11.  
  12. //Activity 1
  13.  
  14. //pet name, age, owner, toy, and neutured or spayed
  15.  
  16. //declaring variables
  17.   $name1 = "Sally";
  18.   $age1 = 9;
  19.   $owner1 = "Greg";
  20.   $fav_toy1 = "chewy bone";
  21.   $NeuOrSprayed1 = "spayed";
  22.  
  23.   $name2 = "Max";
  24.   $age2 = 5;
  25.   $owner2 = "Lisa";
  26.   $fav_toy2 = "cat nip";
  27.   $NeuOrSprayed2 = "neutured";
  28.  
  29.  //output in structured sentence
  30.   echo 'Pet Inforamtion: '.$name1 .' is '. $age1 . ' years old. '. ' Its owner is '.$owner1 . ', its favorite toy is '. $fav_toy1 .' and it is ' . $NeuOrSprayed1;
  31.  
  32.   echo '<br><br>Pet Inforamtion: '.$name2 .' is '. $age2 . ' years old. '. ' Its owner is '.$owner2 . ', its favorite toy is '. $fav_toy2 .' and it is ' . $NeuOrSprayed2;
  33.      
  34.  //declaring variable x and y to hold values 5 and 6
  35.  
  36.   //Declaring a variable in php
  37.       $x = 5;
  38.       $y = 6;
  39.      
  40.       $Sum = $x+ $y;
  41.       echo '<br /><br />The sum is '.$Sum;
  42.      
  43.       $Difference = $y - $x;
  44.       echo '<br /><br />The difference is '.$Difference;
  45.      
  46.       $Product = $x * $y;
  47.       echo '<br /><br />The product is '.$Product;
  48.      
  49.       $Modulus = $y / $x;
  50.       echo '<br /><br />The modulus is '.$Modulus;
  51.  
  52.       //incrementing a
  53.  
  54.       $a = 0;
  55.       $a = ++$x;
  56.  
  57.       echo '<br /><br />The increment is '.$a;
  58.  
  59.       //decrementing b
  60.  
  61.       $b = 0;
  62.       $b = --$y;
  63.  
  64.       echo '<br /><br />The decrement is '.$b;
  65.  
  66.       //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
  67.  
  68.       //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.
  69.  
  70.       //Activity 2
  71.  
  72.       /*
  73.       using if-statements, test and display if the pet from activity 1 is:
  74.         *7 yrs old
  75.         *older than 7 and has an owner named ada
  76.         *named terror or has slipper as favourite toy
  77.       */
  78.  
  79.       if($age1 == 7){
  80.         echo '<br /><br />'."Age is 7";
  81.       } else {
  82.         echo '<br /><br />'."No, Age is not 7";
  83.       }
  84.  
  85.       if($age1 >= 7 && $owner1=="Ada"){
  86.         echo '<br /><br />'."Age is older than 7 whose owner is Ada";
  87.       } else {
  88.         echo '<br /><br />'."No, Age is not older than 7 and its owner is not Ada";
  89.       }
  90.  
  91.       if($name1 == "Terror" || $fav_toy1=="Slipper"){
  92.         echo '<br /><br />'."Name is terror or favourite toy is slipper";
  93.       } else {
  94.         echo '<br /><br />'."Name is not terror nor favourite toy is slipper";
  95.       }
  96.  
  97.       //using the if-else decision structure to display the day of the week based on the current character stored in day
  98.  
  99.       $day = 'U' ;//. 'M' . 'T' . 'W' . 'R' . 'F' . 'S';
  100.  
  101.       if($day == 'U') {
  102.         echo '<br /><br />'."Sunday"; //I helped! ty!
  103.       }
  104.  
  105.       if($day == 'M') {
  106.         echo '<br /><br />'. "Monday";
  107.       }
  108.  
  109.       if($day == 'T') {
  110.         echo '<br /><br />'."Tuesday";
  111.       }
  112.  
  113.       if($day == 'W') {
  114.         echo '<br /><br />'."Wednesday";
  115.       }
  116.  
  117.       if($day == 'R') {
  118.         echo '<br /><br />'."Thursday";
  119.       }
  120.  
  121.       if($day == 'F') {
  122.         echo '<br /><br />'."Friday";
  123.       }
  124.  
  125.       if($day == 'S') {
  126.         echo '<br /><br />'."Saturday";
  127.       }
  128.  
  129.       //using the ternary operator to assess if x is less than y.
  130.  
  131.       if($x < $y) {
  132.         echo '<br /><br />'."X is smaller than y";
  133.       } else {
  134.         echo '<br /><br />'."X is  not smaller than y";
  135.       }
  136.  
  137.       if($x >= $y) {
  138.         echo '<br /><br />'."X is greater than or equals to y";
  139.       } else {
  140.         echo '<br /><br />'."X is less than y";
  141.       }
  142.       //Activity 3
  143.  
  144.       //displaying odd numbers between 0 and 20 in descending order
  145.  
  146.       echo '<br><br>' . "Odd numbers between 0 and 20: ";
  147.      
  148.       for($i=20-1; $i>=0; $i=$i-2) {
  149.           echo '<br><br>' . ($i . "<br>");
  150.       }
  151.  
  152.       //displaying the 7-times table
  153.  
  154.       $count=0;
  155.       $num=7;
  156.  
  157.       while ($count!=13){
  158.         $multiple= $num * $count;
  159.         echo '<br><br>' . $num. 'x'. $count.'='.($multiple . "<br>");
  160.         $count = $count + 1;
  161.       }
  162.  
  163.       //creating the associative array
  164.  
  165.       $course_ranking['Internet Tech'] = 7.5;
  166.       $course_ranking['Info Proj. Management'] = 4;
  167.       $course_ranking['Comp. Network, Arc & Protocol'] = 5;
  168.       $course_ranking['Fundamentals of Research'] = 6;
  169.  
  170.       //displaying the array contents
  171.       echo '<br><br>' . "Course Ranking for Internet Technology is " . $course_ranking['Internet Tech'];
  172.       echo '<br><br>' . "Course Ranking for Information Project Management is " . $course_ranking['Info Proj. Management'];
  173.       echo '<br><br>' . "Course Ranking for Computer Network Architecture & Protocol is " . $course_ranking['Comp. Network, Arc & Protocol'];
  174.       echo '<br><br>' . "Course Ranking for Fundamentals of Research is " . $course_ranking['Fundamentals of Research'] . '<br>';
  175.  
  176.      
  177.       //sorting the array
  178.       $course_ranking = array('Internet Tech'=>7.5, 'Info Proj. Management'=>4, 'Comp. Network, Arc & Protocol'=>5, 'Fundamentals of Research'=>6);
  179.       asort($course_ranking);
  180.  
  181.       foreach($course_ranking as $w => $w_value) {
  182.         echo '<br><br>' . "Course=" . $w . ", Ranking=" . $w_value;
  183.         echo "<br>";
  184.       }
  185.   ?>
  186.   </div>
  187. </body>
  188. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement