tthdoc Posted December 8, 2010 Share Posted December 8, 2010 I am working on modifying some code and wanted to check some variables, but am stuck on something that is probably simple, just over my head. If I do the following: print_r ($this); I get this result (I used PRE tags to format it) ViewList Object ( [_name] => list [_models] => Array ( => ModelList Object ( [_data] => Array ( [0] => stdClass Object ( [id] => 70 [catid] => 1 etc...... Moving down, I typed this... print_r ($this->_models); and get this... Array ( => ModelList Object ( [_data] => Array ( [0] => stdClass Object ( [id] => 70 [catid] => 1 How would I get, for instance, the id? If I try print_r($this->_models->list); nothing happens. In other words, if I wanted to return the id, what would it be -- $this->_models->??? . I tried all kinds of combination's and other ways to do it, just can't figure it out. I know it is my limited knowledge with PHP , so could someone point me in the right direction. Thanks, Doc Link to comment https://forums.phpfreaks.com/topic/221045-help-interpreting-print_r-result/ Share on other sites More sharing options...
Anti-Moronic Posted December 8, 2010 Share Posted December 8, 2010 Have you tried: $this->_models[0]->_data[0]->id; ? Not sure. There should really be some getters and setters for this kind of thing. managing multiple objects can become needlessly complex without them. Link to comment https://forums.phpfreaks.com/topic/221045-help-interpreting-print_r-result/#findComment-1144562 Share on other sites More sharing options...
tthdoc Posted December 8, 2010 Author Share Posted December 8, 2010 Thanks for the quick reply, but no it does not work. I realized when I looked at the post it stripped out some of the text. So I am going to try to use the php tags around it. Here is the $this... ViewList Object ( [_name] => list [_models] => Array ( [list] => ModelList Object ( [_data] => Array ( [0] => stdClass Object ( [id] => 70 [catid] => 1 And here is the $this->models... Array ( [list] => ModelList Object ( [_data] => Array ( [0] => stdClass Object ( [id] => 70 [catid] => 1 Hopefully it does not remove anything this time. It is the list surrounded by brackets that is throwing me... Thanks again. Doc Link to comment https://forums.phpfreaks.com/topic/221045-help-interpreting-print_r-result/#findComment-1144574 Share on other sites More sharing options...
Anti-Moronic Posted December 8, 2010 Share Posted December 8, 2010 Ahh now i see. Yeh, it missed out the list part. Should be: $this->_models['list']->_data[0]->id; If it's not that. try to dig even deeper: print_r($this->_models['list']); print_r($this->_models['list']->_data); etc Link to comment https://forums.phpfreaks.com/topic/221045-help-interpreting-print_r-result/#findComment-1144579 Share on other sites More sharing options...
tthdoc Posted December 8, 2010 Author Share Posted December 8, 2010 Thanks so much, that did it. Doc Link to comment https://forums.phpfreaks.com/topic/221045-help-interpreting-print_r-result/#findComment-1144610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.