Hi, i have a question about php functions when using arrays. I have the following task to do:
1.Create a Php array $months which contains the months of the year, “January”, “February”, “March”, … “December”.
2.Create a Php function called echoArray() which accepts an array as a parameter and uses a for loop to output the following:
Month 1 is January
Month 2 is February
Month 3 is March
…
Month 12 is December
In the following piece of code i have other php code for another task and it does work. So the following code also shows what i have put in for the above task:
<?php
$theFirst=$_POST['firstName'];
$theLast=$_POST['lastName'];
$theAge=$_POST['age'];
$theAddress=$_POST['addressLine1'];
$theTown=$_POST['town'];
$months=array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
function echoArray($theArray)
{
$size=count($theArray);
for ($i=0; $i<=$size; $i++)
echo "month number " . $i . " is :" .$months[$i] . "<br />";
}
echo "Welcome " .$theFirst . " " . $theLast . ". " . " I see you are " . $theAge . " years old and live at " . $theAddress . " , " . $theTown;
?>
I'm not sure if I've done the code right for the array and function as when i load the page onto the internet the code to display the months doesn't appear. However the code to welcome the user does. Can anyone explain what's wrong with the code and what i have to do make it work right. Thank you in advance.