-3
stdClass Object
([abc] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 10

                )

            [1] => stdClass Object
                (
                    [id] => 11

                )

            )

)

I have declared one PHP array. Now I want to get value of id in php variable. How I can get using foreach loop.

4
  • 2
    Please show more effort. This is a mega-duplicate. Commented Jan 16, 2018 at 6:28
  • 1
    You can use following syntax, $myObject->abc[0]->id assuming your object name is $myObject Commented Jan 16, 2018 at 6:30
  • 1
    This question should be closed as a duplicate, not answered. Commented Jan 16, 2018 at 7:59
  • 1
    Possible duplicate of Access a nested object array Commented Jan 16, 2018 at 8:02

2 Answers 2

0

Use

foreach($object->abc as $item)
{
    echo ($item->id);
}
Sign up to request clarification or add additional context in comments.

3 Comments

But it gives me only first array id value
@Anil if you want to get all the values put it in a loop
Code-only answers are low value on StackOverflow
0

You can do it like this:

$id=$abc[0]->id;

1 Comment

Code-only answers are low value on StackOverflow

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.