Page 1 of 1

unexpected T_VARIABLE

Posted: Fri Jul 04, 2003 9:16 am
by MeHigh
I have this code

Code: Select all

<?php
<?php 
$six=6
$arrayname=array("this is the element",5,$six);
echo $arrayname[0];
echo $arrayname[1];
echo $arrayname[2];
?>
?>
and I get this error:

Parse error: parse error, unexpected T_VARIABLE in c:\_server\websites\2.php on line 3

Thanx

Posted: Fri Jul 04, 2003 9:17 am
by []InTeR[]
$six=6 most have a trailing ;
$six=6;

Move to PHP - Normal

Posted: Fri Jul 04, 2003 9:19 am
by MeHigh
thanx a lot.

I'm a begginer.Iguess you noticed :lol:

Posted: Fri Jul 04, 2003 9:29 am
by []InTeR[]
Yes :), but everyone has to begin somewhere....

Posted: Fri Jul 04, 2003 9:44 am
by MeHigh
One more thing:
I have this other code

Code: Select all

<?php
<?php 
$bakery = array(
"cherry" => "5.00",
"cola" => "7.66",
"vanilla" => "4.51",
);

echo "the price for a cherry flavour is $bakery['cherry'] <br>";
echo "the price for a cola flavour is $bakery['cola'] <br>";
echo "the price for a vanilla flavour is $bakery['vanilla'] <br>";

?>
?>
Well..the problem is that I don't get the values.
I only get:

the price for a cherry flavour is
the price for a cola flavour is
the price for a vanilla flavour is

Thanx

Posted: Fri Jul 04, 2003 9:49 am
by twigletmac
You need to change the code so that instead of things like this:

Code: Select all

echo "the price for a cherry flavour is $bakery['cherry'] <br>";
you have

Code: Select all

echo "the price for a cherry flavour is {$bakery['cherry']}<br>";
or

Code: Select all

echo "the price for a cherry flavour is $bakery[cherry]<br>";
or

Code: Select all

echo 'the price for a cherry flavour is '.$bakery['cherry'].'<br>';
Mac

Posted: Fri Jul 04, 2003 10:04 am
by MeHigh
Thanx guys.

One more question: in something like

Code: Select all

<?php
$text = "blblblbllblblblbllbl text text "
?>
how can I enter a simple break?(like <br> for html)
and

what do \n and \r actually do?

Thanx :)

Posted: Fri Jul 04, 2003 10:23 am
by Wayne

Code: Select all

<?php 
$text = "blblblbllblblblbllbl<br> text text <br>" 
?>
\n and \r are the equivalent of pushing the enter key when typing, your code will start on a new line when you view the HTML source code but it will have no affect on what the browser displays.

Just makes it easier to debug your html output.