This article is about how PHP gets all the dates for this week, or all the dates for the last seven days. Hope to help the needy friends
Get all dates this week:
/** * Get all dates this week */function get_week ($time = ', $format = ' y-m-d ') { $time = $time! = '? $time: Time (); Gets the current week $week = Date (' W ', $time); $date = []; for ($i =1; $i <=7; $i + +) { $date [$i] = Date ($format, strtotime (' + '. $i-$week. ' Days ', $time)); } return $date;}
Execution Result:
Print_r (Get_week ()); Array ( [1] = 2018-06-18 [2] = 2018-06-19 [3] = 2018-06-20 [4] = = 2018-06-21 [5] = > 2018-06-22 [6] = 2018-06-23 [7] = 2018-06-24)
Get the date for the last seven days:
/** * Get last seven days all dates */function get_weeks ($time = ', $format = ' y-m-d ') { $time = $time! = '? $time: Time (); Combined data $date = []; for ($i =1; $i <=7; $i + +) { $date [$i] = Date ($format, strtotime (' + '. $i-7. ' Days ', $time)); } return $date;}
Execution Result:
Print_r (Get_weeks ()); Array ( [1] = 2018-06-13 [2] = 2018-06-14 [3] = 2018-06-15 [4] = = 2018-06-16 [5] =& Gt 2018-06-17 [6] = 2018-06-18 [7] = 2018-06-19)
Summarize
The above is a small part of the introduction of PHP to get all the dates of the week or the last seven days all the date method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to you. Thank you very much for the support of the Scripting House website!
Articles you may be interested in:
Comparison of the effects of PHP lcg_value and Mt_rand on generating 0~1 random decimals
How to format a class with ID prefixes via PHP
How to restore print_r processed data to the original array via PHP