Using a php funtion to display an array which contains the months of the year. The function echos month number 1 is January etc. However when I run the code it starts with month number 0 is January, month number 1 is February etc.

Anyone know how to fix this?

<?php    
            function echoArray($theArray)
         {

         $size=count($theArray);

         for ($i=0; $i<=$size; $i++)
        echo "month number " . $i . " is :" .$theArray[$i] . "<br />";
         }




            $months=array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

Array index start from 0. You can +1 within your array loop. Like

for ($i=0; $i<=$size; $i++)
echo "month number " . ($i+1) . " is :" .$theArray[$i] . "<br />";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.