1

this problem is confusing me as i am sure the syntax is correct (although clearly not :-/)

I have an object that looks like this...

[result]  stdClass Object
(
    [aResult] => stdClass Object
        (
            [status] => 0
            [Message] => Success
            [container] => stdClass Object
                (
                    [a] => a
                    [b] => b
                    [c] => c
                    [d] => d
                    [e] => e
                    [f] => f
                    [g] => g
                    [h] => h
                    [i] => i
                    [j] => j
                )

        )

)

No i am trying to pull out the values in the 'container' array. To do this i have the following code...

//pull out array result
    $myDetails = $result->aResult->container;
    foreach( $myDetails as $key)
    {
        echo "<p>";
        echo "<b>a</b>: ".$key->a."<br />";
        echo "<b>b</b>: ".$key->b."<br />";
        echo "<b>c</b>: ".$key->c."<br />";
        echo "<b>d</b>: ".$key->d."<br />";
        echo "<b>e</b>: ".$key->e."<br />";
        echo "<b>f</b>: ".$key->f."<br />";
        echo "<b>g</b>: ".$key->g."<br />";
        echo "<b>h</b>: ".$key->h."<br />";
        echo "<b>i</b>: ".$key->i."<br />";
        echo "<b>j</b>: ".$key->j."<br />";
        echo"</p>";
    }

But all i get is the following error for each of the '$key->X' calls...

Notice: Trying to get property of non-object in

Im honestly unsure what I am doing wrong..... any help is as always greatly appreciated.

3 Answers 3

1

either remove the foreach, or:

foreach( $myDetails as $k=>$v) {
    echo "<b>$k</b>: $v<br />";
}
Sign up to request clarification or add additional context in comments.

1 Comment

posted seconds before me but exactly the same answer!! thanks.
1

Thanks to some joggery form a friend the fix is the following...

//pull out array result
    $myDetails = $result->aResult->container;

    echo "<p>";
    foreach( $myDetails as $key=>$value)
    {

        echo "<b>".$key."</b>: ".$value."<br />";

    }

    echo"</p>";

Comments

0

Variable myDetails contains object, in foreach you are iterating properties of that object, properties is not objects but arrays, so why you see this error message.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.