Nikunj Gondaliya
Nikunj Gondaliya

Reputation: 344

Want to get array value

I have an array like below.

Here, I am getting array key like [_aDeviceTokens:protected] => Array.

$array= ApnsPHP_Message Object
    (
        [_bAutoAdjustLongPayload:protected] => 1
        [_aDeviceTokens:protected] => Array
            (
                [0] => BD74940085E1579333E93B7D172CF82F5A3E0B17617D904107CD77573C42CEC9
            )

        [_sText:protected] => test
        [_nBadge:protected] => 1
        [_sSound:protected] => default
        [_sCategory:protected] => 
        [_bContentAvailable:protected] => 
        [_aCustomProperties:protected] => Array
            (
                [channel_id] => 1xxxx8
                [detail_id] => 1
            )

        [_nExpiryValue:protected] => 1500
        [_mCustomIdentifier:protected] => 
         ) 

As an array have object value so I am trying to get value of this key like,

$array->_aDeviceTokens:protected[0]

But this gives me an error.

So how can I achieve the value of these array keys?

Upvotes: 1

Views: 113

Answers (2)

Progrock
Progrock

Reputation: 7485

It seems you are trying to access protected properties of an object that you are treating like an array.

Looking at the code here: https://github.com/immobiliare/ApnsPHP/blob/master/ApnsPHP/Message.php

There are publically accessible 'getters' for those attributes.

Extract of class ApnsPHP_Message:

public function getCustomIdentifier()
    {
        return $this->_mCustomIdentifier;
    }

So instead of trying to access those properties as you have been, use the corresponding getter.

$custom_identifier = $message->getCustomIdentifier();

Upvotes: 1

msthakur0064
msthakur0064

Reputation: 1455

Convert object to array.

$array = json_decode(json_encode($array),true);

Now, you get value from $array like this

$array['_aDeviceTokens:protected'][0]

Upvotes: 0

Related Questions