CodeIgniter Forums
Get value from object - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Get value from object (/thread-48167.html)

Get value from object - El Forum - 01-06-2012

Probably a very old chestnut but I can't find an answer by searching the forum.

I have an object $record derived from a db. When I run print_r($record) I get:

stdClass Object ( [id] => 4 [qty] => 0 [price] => 3.00 [name] => default [filename] => MH0005.jpg [cat] => agriculture [description] => nil)

so the model is working OK. But now, within a controller method, how can I grab the value of any one of the elements?

I've tried each of these:

$id = $record['id'];
$id = $record[0];
$id = $record->result('id');

but it throws an error every time.