An incoming data feed is in the form of an array. However, each array element contains multiple data fields (both field name and field data). The sample below shows the content of each array element. Using PHP, how do I extract the field names and the associated data?
Thanks for your assistance!
stdClass Object (
[Cancelled] =>
[MessageID] => 999999
[Queued] =>
[ReferenceID] => FRIDAY
[SMSError] => NoError
[SMSIncomingMessages] => stdClass Object (
[SMSIncomingMessage] => stdClass Object (
[FromPhoneNumber] => 1999999999
[IncomingMessageID] => 0byyyyyyy
[Message] => 45-64-07
[ResponseReceiveDate] => 2012-01-07
)
)
[Sent] => 1
[SentDateTime] => 2012-01-07)
What you have isn’t exactly an array, but an object instead, so you have to access it using pointers. I’ll show a couple examples:
In this example, I’ll call your output
$outputIf this were an array, you would call elements like this:
But since this is an stdClass Object, you’ll have to access it like this:
It’s also the same with multi-dimensions:
You can still loop through the object like you would an array, but when you access the elements of the array, they still have to be accessed using a pointer.