Newbie: Array of objects iteration

From: Date: Thu, 08 Oct 2009 20:59:32 +0000
Subject: Newbie: Array of objects iteration
Groups: php.general 
Request: Send a blank email to php-general+get-298781@lists.php.net to get a copy of this message
Hello all, I'm grabbing all records from a table using: $records = $stmt->fetchAll(PDO::FETCH_OBJ); return $records; In order to display the values we can do: foreach ($records as $record) { echo $record->id; echo $record->name; } However, I'd like to grab, also, the *column names*. I've tried: foreach ($records as $column=>$value) { echo "$column is $value\n"; } But I get: "Catchable fatal error: Object of class stdClass could not be converted to string" Can I have your help on how can I properly get the column values? Regards, Márcio

« previous php.general (#298781) next »