You are here: arrays of objects « PHP Programming Language « IT news, forums, messages
arrays of objects

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация