php - Want to get array value
94
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,
$array->_aDeviceTokens:protected[0]
But this gives me an error.
So how can I achieve the value of these array keys?
Answer
Solution:
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:
So instead of trying to access those properties as you have been, use the corresponding getter.
Answer
Solution:
Convert object to array.
Now, you get value from $array like this