faqts : Computers : Programming : Languages : PHP : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 4 people (50%) answered Yes
Recently 2 of 4 people (50%) answered Yes

Entry

When calling a member class of another class, i get Object->variable instead of the variable?
When trying to echo multidimensional arrays I get sth. like array[second_key]. Why is that?

Dec 9th, 2002 12:15
Jens Clasen, Nicholas Gobin,


This occurres when you try to access member objects or multidimensional
arrays in a string. There are two ways to prevent PHP from
misunderstanding the second key/member-name for a generic string:
1. You could simply exclude the object/array from the string and
concatenate the results:
$string="Hello ".$user->data->lastname; and
$string="Hello ".$user[data][lastname]:
2. You could embedd them into "{" and "}":
$string="Hello {$user->data->lastname}"; and
$string="Hello {$user['data']['lastname']}": // remember the quotes!