CodeIgniter Forums
Get value from object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Get value from object (/thread-48167.html)



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

[eluser]Perkin5[/eluser]
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:

Code:
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:

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

but it throws an error every time.