Posted by Rainman on 12/20/05 22:37
I'm having considerable trouble finding the proper syntax for accessing
a specific element from an object which is in an array. Here is my
pertinent code snippet:
$courses = array(); // define empty array
while(($row = mysql_fetch_object($result))) {
array_push($courses,$row); // push row object onto the array
}
echo "<p>$courses[0]->name</p>\n"; // access first object's name
This does not give me the string I want, which is name of the first
course in the array. I verified $courses[0] is an object. One of the
members of the object is 'name'. How do I access the name of the first
course?
I tried:
$courses[0]->name
${courses[0]}->name
$courses[0]['name']
${courses[0]->name}
and other combinations I could think of. Which way is the correct way?
Mark
Navigation:
[Reply to this message]
|