0

My array looks like this. (see code below)

Lets say I want to access [value] in [visibiltiyindex] . And also [value] in [pagerank].

The code I came up with:

print_r ($results->answer->{"0"}->visibilityindex->{"0"}->value);
print_r ($results->answer->[0]->visibilityindex->[0]->value);
print_r ($results->answer->visibilityindex->value);

All code examples above wont work. I am using php 5.2, so array_map and array_column wont work for me.

I checked out this post and this one, but their methods dont work for me either since my array is even more multidimensional... Especially the [0] is irritating me.

My array:

stdClass Object
(
    [api_key] => Array
        (
            [0] => json
        )

    [method] => Array
        (
            [0] => domain.overview
        )

    [answer] => Array
        (
            [0] => stdClass Object
                (
                    [visibilityindex] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [domain] => spiegel.de
                                    [date] => 2014-03-17T00:00:00+01:00
                                    [value] => 372.4821 (I WANT THIS VALUE)
                                )

                        )

                    [pagerank] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [domain] => spiegel.de
                                    [date] => 2008-07-26T00:00:00+02:00
                                    [value] => 8  (I WANT THIS VALUE ALSO)
                                )

                        )

                    [pages] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [domain] => spiegel.de
                                    [date] => 2014-03-17T00:00:00+01:00
                                    [value] => 1130000
                                )

                        )

                    [age] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [domain] => spiegel.de
                                    [value] => 1996-12-23T00:00:00+01:00
                                )

                        )

                    [kwcount.seo] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [domain] => spiegel.de
                                    [date] => 2014-03-17T00:00:00+01:00
                                    [value] => 199022
                                )

                        )

                    [kwcount.sem] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [domain] => spiegel.de
                                    [date] => 2014-03-17T00:00:00+01:00
                                    [value] => 317
                                )

                        )

                )

        )

    [credits] => Array
        (
            [0] => stdClass Object
                (
                    [used] => 6
                )

        )

)

What can I do to only access those two values? Does it have to be a loop?

1 Answer 1

0

answer and visibilityIndex are arrays, so you need this:

$results->answer[0]->visibilityIndex[0]->value
Sign up to request clarification or add additional context in comments.

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.