0

Please can someone tell me what I am doing wrong here because it is giving me a blank result. just a newbie wanting to learn.

$months = "2";
$month = array(1=>January,"2"=>February,"3"=>March,"4"=>April,"5"=>May,"6"=>June,"7"=>July,"8"=>August,"9"=>September,"10"=>October,"11"=>November,"12"=>December);
$description = 'In respect of '.$particular.' collection for the month of ';print  $month['$months'];

echo $description

1 Answer 1

1

You haven't enclosed the array string values in quotes. Change your $month definition to this:

$month = array(
     1 => "January",
     2 => "February",
     3 => "March",
     4 => "April",
     5 => "May",
     6 => "June",
     7 => "July",
     8 => "August",
     9 => "September",
    10 => "October",
    11 => "November",
    12 => "December"
);

Also, you don't really need to create an associative array for the month names. You can get a month's name from its number like this:

$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
Sign up to request clarification or add additional context in comments.

Comments

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.