fork(1) download
  1. <?php
  2.  
  3. $dia = "01";
  4. $mes = "04";
  5. $ano = "2018";
  6. $data = $dia."-".$mes."-".$ano;
  7.  
  8. $dia_da_semana_array = array('Domingo', 'Segunda', 'Terca', 'Quarta', 'Quinta', 'Sexta', 'Sabado'); // lista
  9. $meses_array = array('', 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'); // lista
  10. $dia_da_semana_inicial = date('w', strtotime($data)); // pega o dia da semana em inteiro
  11. $dia_da_semana_inicial_string = $dia_da_semana_array[$dia_da_semana_inicial]; // pega o dia da semana em string
  12.  
  13. $arraySemanas = array(); // lista das semanas
  14.  
  15. $x = (int)$dia_da_semana_inicial;
  16. $y = 0;
  17.  
  18. $semana = 1;
  19. while(true){
  20.  
  21. // insere no array
  22. $indexMes = (int)$mes;
  23. $arraySemanas[$semana][$y]['day_week'] = $data;
  24. $arraySemanas[$semana][$y]['day_name'] = $dia_da_semana_array[$x];
  25. $arraySemanas[$semana][$y]['month_name'] = $meses_array[$indexMes];
  26.  
  27. // verifica se mudou o mês
  28. $data = date('d-m-Y', strtotime("+1 day", strtotime($data)));
  29. $dataVerifi = explode("-", $data);
  30. if($dataVerifi[1] != $mes){
  31. // se mudou o mes para o loop
  32. break;
  33. }
  34.  
  35. if($x == 6){
  36. $x = 0;
  37. $y = 0;
  38. $semana++;
  39. } else {
  40. $x++;
  41. $y++;
  42. }
  43.  
  44. }
  45.  
  46. print_r(json_encode($arraySemanas));
Success #stdin #stdout 0.02s 24144KB
stdin
Standard input is empty
stdout
{"1":[{"day_week":"01-04-2018","day_name":"Domingo","month_name":"Abril"},{"day_week":"02-04-2018","day_name":"Segunda","month_name":"Abril"},{"day_week":"03-04-2018","day_name":"Terca","month_name":"Abril"},{"day_week":"04-04-2018","day_name":"Quarta","month_name":"Abril"},{"day_week":"05-04-2018","day_name":"Quinta","month_name":"Abril"},{"day_week":"06-04-2018","day_name":"Sexta","month_name":"Abril"},{"day_week":"07-04-2018","day_name":"Sabado","month_name":"Abril"}],"2":[{"day_week":"08-04-2018","day_name":"Domingo","month_name":"Abril"},{"day_week":"09-04-2018","day_name":"Segunda","month_name":"Abril"},{"day_week":"10-04-2018","day_name":"Terca","month_name":"Abril"},{"day_week":"11-04-2018","day_name":"Quarta","month_name":"Abril"},{"day_week":"12-04-2018","day_name":"Quinta","month_name":"Abril"},{"day_week":"13-04-2018","day_name":"Sexta","month_name":"Abril"},{"day_week":"14-04-2018","day_name":"Sabado","month_name":"Abril"}],"3":[{"day_week":"15-04-2018","day_name":"Domingo","month_name":"Abril"},{"day_week":"16-04-2018","day_name":"Segunda","month_name":"Abril"},{"day_week":"17-04-2018","day_name":"Terca","month_name":"Abril"},{"day_week":"18-04-2018","day_name":"Quarta","month_name":"Abril"},{"day_week":"19-04-2018","day_name":"Quinta","month_name":"Abril"},{"day_week":"20-04-2018","day_name":"Sexta","month_name":"Abril"},{"day_week":"21-04-2018","day_name":"Sabado","month_name":"Abril"}],"4":[{"day_week":"22-04-2018","day_name":"Domingo","month_name":"Abril"},{"day_week":"23-04-2018","day_name":"Segunda","month_name":"Abril"},{"day_week":"24-04-2018","day_name":"Terca","month_name":"Abril"},{"day_week":"25-04-2018","day_name":"Quarta","month_name":"Abril"},{"day_week":"26-04-2018","day_name":"Quinta","month_name":"Abril"},{"day_week":"27-04-2018","day_name":"Sexta","month_name":"Abril"},{"day_week":"28-04-2018","day_name":"Sabado","month_name":"Abril"}],"5":[{"day_week":"29-04-2018","day_name":"Domingo","month_name":"Abril"},{"day_week":"30-04-2018","day_name":"Segunda","month_name":"Abril"}]}