You have a PHP array called inventory. This array is indexed by keys. The keys a
ID: 3868136 • 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
$inventory=array('Milk' => '30/08/2017','Cheese' => '08/08/2017',"Flour"=>"17/08/2017"); //You can add more
$date1=date('d/m/Y'); //current date in dd/mm/yy format
$NewDate=Date('d/m/y', strtotime("+4 days")); //new date after 3 days to compare after 3 days
$NewDate1=Date('d/m/y', strtotime("+8 days"));//new date after 7 days to compare date for after week
foreach($inventory as $x => $x_value)
{
if($NewDate1<=$x_value)
{
echo $x." is Normal<br>";
}
if($date1>=$x_value )
{
echo $x." is Urgent<br>";
}
elseif($NewDate>=$x_value )
{
echo $x." is attention<br>";
}
}
output :
Milk is Normal
Cheese is Urgent
Flour is Urgent
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.