Mark Sargent wrote:
Hi All,

this code,

<?php
$flavour[] = "blue raspberry";
$flavour[] = "root beer";
$flavour[] = "pineapple";
sort($flavour);
print_r($flavour);
echo "<br>";
echo "My favourite flavours are:<br>";
    foreach ($flavour as $currentValue) {
       //these lines will execute as long as there is a value in $flavour
       echo $currentValue "<br>\n";
    }
?>


gives this,

*Parse error*: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in */usr/local/apache2/htdocs/sorting.php* on line *18

The echo in the foreach loop has no concatenation operator.

echo $currentValue "<br>\n";

should be

echo $currentValue."<br>\n";

> and adding a , to this line,
>
>       foreach ($flavour, as $currentValue) {
>
> gives this error,
>
> *Parse error*: syntax error, unexpected ',' in
> */usr/local/apache2/htdocs/sorting.php* on line *16*
>
> The code in the book I'm following has the , in that line. Can anyone
> tell me what I'm doing wrong? Cheers.

If the code in the book you're reading really has a , in the foreach line I suggest you throw it away and find another book, because that's not valid PHP.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to