A simple "foreach" question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bmpwe
Forum Newbie
Posts: 3
Joined: Fri Sep 20, 2002 12:06 am

A simple "foreach" question.

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 { }
bmpwe
Forum Newbie
Posts: 3
Joined: Fri Sep 20, 2002 12:06 am

Ahh...

Post 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
Post Reply