0

I was wondering how I could go about accessing values within an object, such as 'backpackPosition'? I'm guessing I would have to put it in some kind of foreach loop, but I have no idea how to get the values.

TF2Inventory Object
(
[fetchDate] => 1234541231
[items] => Array
(
    [60] => TF2Item Object
        (
            [equipped] => Array
                (
                    [scout] => 1
                    [sniper] => 1
                    [soldier] => 1
                    [demoman] => 1
                    [medic] => 1
                    [heavy] => 1
                    [pyro] => 1
                    [spy] => 1
                )

            [attributes] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => custom employee number
                            [class] => set_employee_number
                            [value] => 0
                        )

                    [1] => stdClass Object
                        (
                            [name] => cannot trade
                            [class] => cannot_trade
                            [value] => 1
                        )

                )

            [backpackPosition] => 61
            [className] => tf_wearable
            [count] => 1
            [defindex] => 170
            [id] => 535518002
            [level] => 20
            [name] => Primeval Warrior
            [quality] => unique
            [slot] => misc
            [tradeable] => 
            [type] => Badge
        )

    [43] => TF2Item Object
        (
            [equipped] => Array
                (
                    [scout] => 0
                    [sniper] => 0
                    [soldier] => 0
                    [demoman] => 0
                    [medic] => 0
                    [heavy] => 0
                    [pyro] => 0
                    [spy] => 0
                )

            [attributes] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => cannot trade
                            [class] => cannot_trade
                            [value] => 1
                        )

                )

            [backpackPosition] => 44
            [className] => tf_wearable
            [count] => 1
            [defindex] => 471
            [id] => 535518003
            [level] => 50
            [name] => Proof of Purchase
            [quality] => unique
            [slot] => head
            [tradeable] => 
            [type] => Hat
        )

    [42] => TF2Item Object
        (
            [equipped] => Array
                (
                    [scout] => 1
                    [sniper] => 1
                    [soldier] => 1
                    [demoman] => 1
                    [medic] => 1
                    [heavy] => 1
                    [pyro] => 1
                    [spy] => 1
                )

            [attributes] => 
            [backpackPosition] => 43
            [className] => tf_wearable
            [count] => 1
            [defindex] => 278
            [id] => 541628464
            [level] => 31
            [name] => Horseless Headless Horsemann's Head
            [quality] => unique
            [slot] => head
            [tradeable] => 
            [type] => Hat
        )

    [59] => TF2Item Object
        (
            [equipped] => Array
                (
                    [scout] => 0
                    [sniper] => 0
                    [soldier] => 0
                    [demoman] => 0
                    [medic] => 0
                    [heavy] => 0
                    [pyro] => 0
                    [spy] => 0
                )

            [attributes] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => cannot trade
                            [class] => cannot_trade
                            [value] => 1
                        )

                )

            [backpackPosition] => 60
            [className] => tf_wearable
            [count] => 1
            [defindex] => 115
            [id] => 548155039
            [level] => 10
            [name] => Mildly Disturbing Halloween Mask
            [quality] => unique
            [slot] => head
            [tradeable] => 
            [type] => Holiday Hat
        )
1
  • Examples should be minimized, and presented as code, not variable dumps (which aren't useable). As for accessing properties, your question is under-specified. Do you mean how do you access them when the names may vary? Why can't you use something like $inventory->items[0]->backpackPosition? Commented Jan 16, 2012 at 20:03

1 Answer 1

2
foreach($inventory_object->items as $item)
{
    $item->backpackPosition;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is direct access. The OP referenced foreach also.

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.