Page 1 of 1

A simple "foreach" question.

Posted: Fri Sep 20, 2002 12:06 am
by bmpwe
Hi,

I recently took it upon my self to learn PHP. I picked up a book and am in the middle of a lesson when I ran into a problem I can't seem to fix.

The assignment is to create a multi-demensional array of movie genres and titles for each of those genres, and then print it. I'm geting an error in line 10.

Code: Select all

<?php
			
		 	$db=array 
		 	(
		 		array('SF','Terminator','Star Trek','Star Wars','The Matrix'),
				array('Action','Indinia Jones','The Mummy','Top Gun','Days of Thunder'),
				array('Romance',"You've Got Mail",'Sleapless in Seatle','Gone with the Wind','Bed of Roses')
			)
			
			foreach($db as $temp)
			(
				print("Genere:");
				foreach($temp as $name)
					print(" $name<br>");
				print("<br>");
			)
					
				
		   ?>

Any help would be much appreciated.

Thanks,
Brandon

Posted: Fri Sep 20, 2002 12:18 am
by volka

Code: Select all

&lt;?php 
$db=array( 
			array('SF','Terminator','Star Trek','Star Wars','The Matrix'), 
			array('Action','Indinia Jones','The Mummy','Top Gun','Days of Thunder'), 
			array('Romance',"You've Got Mail",'Sleapless in Seatle','Gone with the Wind','Bed of Roses') 
		);

foreach($db as $temp) 
{ 
	print("Genere:"); 
	foreach($temp as $name) 
	print(" $name&lt;br&gt;"); 
	print("&lt;br&gt;"); 
} 
?&gt;
you forgot a ; to close the array-statement and code-blocks are enclosed by { }

Ahh...

Posted: Fri Sep 20, 2002 12:43 am
by bmpwe
Ok, thanks. I could have sworn the book I was reading from had it that way, but upon examination I found it did.

Thanks