0

I got a response like this now i want to print

[products] how to print

i try this print_r($response['products']);

My Response

stdClass Object
(
    [users] => Array
        (
            [0] => stdClass Object
                (
                    [username] => admin
                    [firstName] => admin
                    [lastName] => admin


                    [products] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [name] => 1
                                    [url] => mytest.html
                                )

                            [1] => stdClass Object
                                (
                                    [name] => 2
                                    [url] => mytest.html
                                )

                            [2] => stdClass Object
                                (
                                    [name] => 3
                                    [url] => mytest.html
                                )

                            [3] => stdClass Object
                                (
                                    [name] => 4
                                    [url] => mytest.html
                                )

                            [4] => stdClass Object
                                (
                                    [name] => 5
                                    [url] => mytest.html
                                )

                            [5] => stdClass Object
                                (
                                    [name] => 6
                                    [url] => mytest.html
                                )

                            [6] => stdClass Object
                                (
                                    [name] => 7
                                    [url] => mytest.html
                                )

                        )
                )

        )

    [error] => 
    [errorMessage] => 
)
3
  • 1
    $response->users[0]->products[0]->name for example. Commented Mar 7, 2018 at 13:47
  • php.net/manual/en/control-structures.foreach.php Commented Mar 7, 2018 at 13:55
  • I don't want to foreach i used thease to some varibles Commented Mar 7, 2018 at 14:00

1 Answer 1

2

Try This one

print_r($response->users['0']->products);
Sign up to request clarification or add additional context in comments.

6 Comments

i need to print all products
The above should print all the indexes from 0 to 6. You can try foreach if you want each array to be shown one at a time like this: ============================================ foreach($response->users['0']->products as $single_product): print_r($single_product); endforeach;
how to get only names
Names can be obtained this way : ============================= foreach($response->users['0']->products as $single_product): echo $single_product['name']; endforeach;
in same way i want to all name not foreach
|

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.