php - Want to get array value


I have an array like below.

Here, I am getting arraykey 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,


But this gives me an error.

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




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

Looking at the code here:

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();



Convert object to array.

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

Now, you get value from $array like this


People are also looking for solutions to the problem: Cannot send multiple mysql queries to my database via php


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.