We help IT Professionals succeed at work.
Get Started

HTML PHP foreach loop of array not displayed to page.

Steve7423
Steve7423 asked
on
442 Views
Last Modified: 2014-07-07
I've copied code from 3wSchools.com in an effort to learn html and php.  if I run the script below all I get on the screen is:     "; } ?>


      <html>
      <head>
      <body>

<?php
$colors = array("red","green","blue","yellow");
foreach ($colors as $value)
   {
   echo "$value <br>";
   }
?>

      </body>
      </html>



What should be displayed is :

red
green
blue
yellow


this is my first week with html and I'm completely bewildered as to why this isn't working.  I've tried multiple different possibilities for arrays and loops and nothing works.  

is there a problem with the code or my environment?  what would cause this?  why can I not print out elements of an array?

the object of the game is to loop through an array and display it in a table, however first I have to get an array to display, and it won't !

Help is appreciated.
Comment
Watch Question
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE