Page 1 of 1
Array Problems
Posted: Fri Jun 23, 2006 11:00 am
by tsalexey544
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
It is me again
I can't understand what is wrong with this php script. Pleaz help me.
Code: Select all
<?php
$tseitlin = array(
"Alex" => array("18","Tennis"),
"Daniel" => array("14", "basketball"),
);
echo "Alexey is" $tseitlin['Alex'][0] "years old.";
?>
Pimptastic | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Jun 23, 2006 11:03 am
by JayBird
What's the problem?
At a glance the line should be like this
Code: Select all
echo "Alexey is".$tseitlin['Alex'][0]."years old.";
Posted: Fri Jun 23, 2006 11:04 am
by Robert Plank
You forgot your concatenation operators big guy.
Code: Select all
<?php
$tseitlin = array(
"Alex" => array("18","Tennis"),
"Daniel" => array("14", "basketball"),
);
echo "Alexey is " . $tseitlin['Alex'][0] . " years old.";
?>
Posted: Fri Jun 23, 2006 11:05 am
by tsalexey544
I get this..............
Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Program Files\DzSoft\PHP Editor\php26.tmp on line 15
Posted: Fri Jun 23, 2006 11:06 am
by JayBird
WOuld help if we could see what was on line 15
Posted: Fri Jun 23, 2006 11:08 am
by Robert Plank
tsalexey544 wrote:I get this..............
Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Program Files\DzSoft\PHP Editor\php26.tmp on line 15
That's the error I was getting too, and then I added the dots, the code I posted as a reply worked for me.
Posted: Fri Jun 23, 2006 11:08 am
by tsalexey544
This is line
15
Code: Select all
echo "Alexey is" $tseitlin['Alex'][0] "years old.";
Posted: Fri Jun 23, 2006 11:09 am
by Robert Plank
Like I said change that to
Code: Select all
echo "Alexey is " . $tseitlin['Alex'][0] . " years old.";
And it will work.
Posted: Fri Jun 23, 2006 11:09 am
by JayBird
Where are your concatenation operators?
Posted: Fri Jun 23, 2006 11:11 am
by tsalexey544
Posted: Fri Jun 23, 2006 11:17 am
by tsalexey544
I add 3 arrays and I started geting errors on the first echo line.
Code: Select all
<?php
$tseitlin = array(
"Alex" => array("18","Tennis"),
"Daniel" => array("14", "basketball"),
);
echo "Alexey is " . $tseitlin['Alex'][0] . " years old. And he likes to play" . $tseitlin['Alex'][1] . ;
echo "My brother is " . $tseitlin['Daniel'][0] . " years old. And he likes to play" . $tseitlin['Daniel'][1] . ;
?>
Posted: Fri Jun 23, 2006 11:18 am
by feyd
remove the trailing dots.
Posted: Fri Jun 23, 2006 11:20 am
by tsalexey544
From this:
Code: Select all
echo "Alexey is " . $tseitlin['Alex'][0] . " years old. And he likes to play" . $tseitlin['Alex'][1] . ;
echo "My brother is " . $tseitlin['Daniel'][0] . " years old. And he likes to play" . $tseitlin['Daniel'][1] . ;
to this?
Code: Select all
echo "Alexey is " . $tseitlin['Alex'][0] . " years old. And he likes to play" $tseitlin['Alex'][1];
echo "My brother is " . $tseitlin['Daniel'][0] . " years old. And he likes to play" $tseitlin['Daniel'][1];
Posted: Fri Jun 23, 2006 11:21 am
by tsalexey544
Posted: Fri Jun 23, 2006 11:25 am
by JayBird
no to this
Code: Select all
echo "Alexey is " . $tseitlin['Alex'][0] . " years old. And he likes to play" . $tseitlin['Alex'][1];
echo "My brother is " . $tseitlin['Daniel'][0] . " years old. And he likes to play" . $tseitlin['Daniel'][1];
then read this -
http://uk.php.net/manual/en/language.op ... string.php
Remember how i told you the manual is brilliant and how you should love it
