hedhud
hedhud

Reputation: 73

Foreach loops thru an object

How do i loop thru this object and read the conversion_id. I tried the following foreach, but i seems like I'm doing it wrong.

<?php
    foreach( $result->response->data as $key=>$value ) {
        echo $value->Stat->conversion_id.' ';
    }
?>





stdClass Object
(
    [response] => stdClass Object
        (
            [status] => 1
            [data] => stdClass Object
                (
                    [data] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [Stat] => stdClass Object
                                        (
                                            [conversion_id] => 351140
                                        )
                                )

                            [1] => stdClass Object
                                (
                                    [Stat] => stdClass Object
                                        (
                                            [conversion_id] => 355704
                                        )
                                }
                        )
                )
        )

)

Upvotes: 0

Views: 63

Answers (2)

Skpd
Skpd

Reputation: 670

You missed "data" and "Stat" objects:

<?php
    foreach( $result->response->data->data as $key=>$value ) {
        echo $value->Stat->conversion_id;
    }
?>

Upvotes: 2

Eric
Eric

Reputation: 97691

You want to iterate over $result->response->data->data

Upvotes: 2

Related Questions