fork download
  1. <?php
  2.  
  3. //domingo 0
  4. //segunda 1
  5. //terça 2
  6. //quarta 3
  7. //quinta 4
  8. //sexta 5
  9. //sabado 6
  10. //0 (para domingo) até 6 (para sábado)
  11.  
  12.  
  13. function render($date = null)
  14. {
  15. $current = is_null($date)
  16. ? date('w')
  17. : date('w', strtotime($date));
  18.  
  19. $now = is_null($date)
  20. ? strtotime('now')
  21. : strtotime($date);
  22.  
  23. $week = ['dom' => '',
  24. 'seg' => '',
  25. 'ter' => '',
  26. 'qua' => '',
  27. 'qui' => '',
  28. 'sex' => '',
  29. 'sab' => ''];
  30. $keys = array_keys($week);
  31. if ($current > 0)
  32. {
  33. $now = strtotime('-'.($current).' day', $now);
  34. }
  35. for($i = 0; $i < 7; $i++)
  36. {
  37. $week[$keys[$i]] = date('d/m/Y',
  38. strtotime("+$i day", $now));
  39. }
  40. return $week;
  41. }
  42.  
  43.  
  44. var_dump(render());
  45. var_dump(render('2017-08-06'));
  46.  
Success #stdin #stdout 0.01s 83904KB
stdin
Standard input is empty
stdout
array(7) {
  ["dom"]=>
  string(10) "13/08/2017"
  ["seg"]=>
  string(10) "14/08/2017"
  ["ter"]=>
  string(10) "15/08/2017"
  ["qua"]=>
  string(10) "16/08/2017"
  ["qui"]=>
  string(10) "17/08/2017"
  ["sex"]=>
  string(10) "18/08/2017"
  ["sab"]=>
  string(10) "19/08/2017"
}
array(7) {
  ["dom"]=>
  string(10) "06/08/2017"
  ["seg"]=>
  string(10) "07/08/2017"
  ["ter"]=>
  string(10) "08/08/2017"
  ["qua"]=>
  string(10) "09/08/2017"
  ["qui"]=>
  string(10) "10/08/2017"
  ["sex"]=>
  string(10) "11/08/2017"
  ["sab"]=>
  string(10) "12/08/2017"
}