Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Code producing syntax error-and i don't know why?
Old 06-30-2010, 03:16 PM Code producing syntax error-and i don't know why?
Junior Talker

Posts: 3
Trades: 0
Hi, This code for some reason is producing a syntax error from this line:
foreach ($types = 0; $types < 4; $types++) and i can't figure out why. Can anyone help? Please!

PHP Code:
<?php // Script  10.6 - create-four-cell-table
     // This script creates a four cell  table.

   // Address error handling.
   
ini_set  ('display_errors'1);
   
error_reporting (E_ALL & ~E_NOTICE);
function  
tea ($types){
$types = array ("Chinese Green""Japanese Red",  "Korean Black""British White");
foreach (
$types 0$types 4;  $types++) {
echo 
"<tr><td> "$types ."
</tr></td>"
;
}
}
?>
<!DOCTYPE  HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta  http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Teas  of the World!</title>
</head>
<body>
<table>
<?php  echo tea()?>
</table>
</body>
</html>

Last edited by chrishirst; 06-30-2010 at 03:18 PM..
canadian_angel is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-30-2010, 03:25 PM Re: Code producing syntax error-and i don't know why?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP Arrays are 0 based so your array is 0 .. 3 NOT 0 .. 4

You also have the wrong syntax for a foreach loop.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-30-2010, 07:38 PM Re: Code producing syntax error-and i don't know why?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Why does the function tea take the parameter $types, but then set it to a new value?

As Chris pointed out, you are using for loop syntax with a foreach loop. Try:
PHP Code:
foreach($types as $t)
{
     echo 
"<tr><td> "$t ."</tr></td>";

or

PHP Code:
for($i 0$i count($types); $i++)
{
     echo 
"<tr><td> "$types[$i] ."</tr></td>";

Also, you forgot your ; on this line:
PHP Code:
<?php  echo tea()?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Code producing syntax error-and i don't know why?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17428 seconds with 12 queries