Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have a PHP array called inventory. This array is indexed by keys. The keys a

ID: 3843631 • Letter: Y

Question

You have a PHP array called inventory. This array is indexed by keys. The keys are product names and the values are expiration dates. The expiration dates are in the format MM/DD/YYYY. The array might look something like: $inventory = array("Milk" => "03/2/2013", "Cheese" => "04/02/1990", "flour" => "05/06/2027"); Get the current time and create an XHTML table where the first column consists of keys in this array and the second column consists of dates. For each table row write a class attribute with one of 3 values: normal, attention, urgent. The table row should get one of 3 class attributes depending on the date. If the product's expiration date is more than a week away (7 days away in the future), the class attribute's value should be normal. If the product's expiration is 3 days in the future, the class attribute should be attention. If the product is expiring today or has already expired, the class attribute should be urgent.

Explanation / Answer

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<?php
$inventory=array("Milk"=>"03/2/2013","Cheese"=>"04/02/1990","Flour"=>"05/06/2027")
          

?>
<table>
  
  
<tr>
<th>Product Name</th>
<th>Expiration date</th>
<th>Status</th>
</tr>

<?php
   foreach($inventory as $key=> $value){
       $dt=date("m/d/y");
       $status = date($inventory[$key]);
       $status_date=date_diff(date_create(date("m/d/y")),date_create(date($inventory[$key])));

//Stores the diference in current date and product expiration date

       $diff=$status_date->format("%R%a"); //Find out difference in no. of days
       if($diff>=7){$status="Normal";}
       else if($diff<=3){$status="Atttention";}
       if($diff<=0){$status="Urgent";}
?>
   <tr>
       <td><?php echo $key;?></td>
       <td><?php echo $value;?></td>
       <td><?php echo $status;?></td>
   </tr>
   <?php } ?>
</table>

</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote