0

i have an output in a object

it looks like below,

stdClass Object
    (
        [0] => stdClass Object
            (
                [id] => 14
                [tcaseid] => 11
                [step] => a
                [teststep] => a
                [expected_data] => a
                [actual_result] => a
                [pass_fail] => 1
                [notes] => a
            )

        [1] => stdClass Object
            (
                [id] => 15
                [tcaseid] => 11
                [step] => b
                [teststep] => b
                [expected_data] => b
                [actual_result] => b
                [pass_fail] => 1
                [notes] => b
            )

        [2] => stdClass Object
            (
                [id] => 16
                [tcaseid] => 11
                [step] => d
                [teststep] => d
                [expected_data] => d
                [actual_result] => d
                [pass_fail] => 1
                [notes] => d
            )

        [3] => stdClass Object
            (
                [id] => 17
                [tcaseid] => 11
                [step] => e
                [teststep] => e
                [expected_data] => e
                [actual_result] => e
                [pass_fail] => 1
                [notes] => e
            )

        [id] => 11
        [project_id] => 1
        [title] => title
        [description] => desc
        [module_id] => 1
        [usecaseid] => 1
        [tcaseid] => 5
    )

my question is how to get this value ( [id] => 11 )

i have tried

* $data->id

* $data['id'];

any help?

5
  • 1
    $data->id didn't work? how about echo $data->id;? Commented Mar 4, 2015 at 4:29
  • yes trying echo $data->id; also gives error. Commented Mar 4, 2015 at 4:36
  • There is already an answer for this here stackoverflow.com/questions/9474446/… Commented Mar 4, 2015 at 4:40
  • use get_object_vars() function. $data = get_object_vars($data); print_r($data);. i hope this help Commented Mar 4, 2015 at 4:43
  • thanks to all. finally worked Commented Mar 4, 2015 at 4:52

1 Answer 1

1

You can try

$data[4]['id']; 

Link For Ref: http://www.if-not-true-then-false.com/2009/php-tip-convert-stdclass-object-to-multidimensional-array-and-convert-multidimensional-array-to-stdclass-object/

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your reply. actual the size of object is not fixed.

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.