Array Problems

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
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Array Problems

Post by tsalexey544 »

Pimptastic | Please use

Code: Select all

,

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

,

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]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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.";
Last edited by JayBird on Fri Jun 23, 2006 11:04 am, edited 1 time in total.
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post 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.";
?>
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

WOuld help if we could see what was on line 15
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post 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.
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Post by tsalexey544 »

This is line 15

Code: Select all

echo "Alexey is" $tseitlin['Alex'][0] "years old.";
Robert Plank
Forum Contributor
Posts: 110
Joined: Sun Dec 26, 2004 9:04 pm
Contact:

Post by Robert Plank »

Like I said change that to

Code: Select all

echo "Alexey is " . $tseitlin['Alex'][0] . " years old.";
And it will work.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Where are your concatenation operators?
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Post by tsalexey544 »

Code: Select all

Thanks A LOT. Now I get it!!!
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Post 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] . ;
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remove the trailing dots.
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Post 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];
tsalexey544
Forum Commoner
Posts: 41
Joined: Thu Jun 22, 2006 11:19 am

Post by tsalexey544 »

Code: Select all

it didn't work
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

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