1

Hi guys this is my code:

$Months = array(
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sep',
    'Oct',
    'Nov',
    'Dec'
);


foreach($Months as $value){  
    echo "$value ";
    echo date('Y');
    echo "<br>";

    foreach(range(1,31) as $Days) {
        echo $Days;
         echo " ";
    }

    echo "<br>";
}

and this is the output:

Jan 2017

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 

Feb 2017

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 

and so on.

How can I edit the index to output the following months and it's days.

1
  • I am not quite sure what the desired output is. Can you also hardcode an example in your question? Commented Oct 2, 2017 at 1:38

1 Answer 1

4
foreach($Months as $key=>$value){  
    echo "$value ";
    echo date('Y');
    echo "<br>";
    $year = 2017;
    echo implode(" ", range(1, cal_days_in_month(CAL_GREGORIAN, $key+1, $year)));

    echo "<br>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Suggestion: you have the range of dates range(1, cal_days_in_month(CAL_GREGORIAN, $key+1, $year)) in an array. Why loop to echo it? You can justecho implode(" ", range(1, cal_days_in_month(CAL_GREGORIAN, $key+1, $year)));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.