Hi guys. I am new to posting but have been browsing for awhile now. I am in the process of learning PHP on my own and its not coming to well ATM. So I have a little coding down but I am stuck on this problem:

/ Using only a array and a foreach loop, write a program that prints the days of the week \

$days = array {
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
};

//This is where I need help with the code

      echo  "$day \r\n";

?>

Thanks in advance!

    Well for starters, you've got two parse errors before we even get to your 'This is where i need help' message:

    1. To end comment blocks opened with '/*', you need to use '/' - not '\'.

    2. The syntax to create an [man]array[/man] is array() (with parentheses), not array{} (with curly braces/brackets). See the manual page for [man]array[/man] for more info/examples.

    As for the rest... what have you tried? The manual page for [man]foreach[/man] explains how to use such loops and includes several examples.

      Ive tried this:

      foreach ($days as $day)
      {

      echo $day . "\r\n";
      }

        Looks fine to me, assuming you correct the two parse errors I mentioned above.

          Write a Reply...