Jump to content

Help interpreting print_r result...


tthdoc

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.