Retrieving a value from a multidimensional array
Hello, so I am using the callback function https://smsgateway.me and my current code is here:
<?php
include "smsGateway.php";
$smsGateway = new SmsGateway('email@gmail.com', 'password');
$message = //extract number value from multidimensional array;
$number = "09058789624";
$deviceID = 5495;
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID);
?>
In the smsgateway.me documentation here I have used every HTTP POST request and as you can see the contact with the parameter there says that it is a multidimensional array that contains ID, name and number. Now I just wanted to get a number. How can i do this?
+3
source to share
2 answers
Since the response is in JSON, you do something like the following:
$json = json_decode($result);
echo $json->result->success->contact->number;
Of course, you should also add error handling and check if the object exists, etc.
For reference, I used the documentation that describes the response that is returned when posting a message, as noted here: Send message to number
Response format (for success) :
{
"success":true,
"result":{
"success":[
{
"id":"308",
"device_id":"4",
"message":"hello world!",
"status":"pending",
"send_at":"1414624856",
"queued_at":"0",
"sent_at":"0",
"delivered_at":"0",
"expires_at":"1414634856",
"canceled_at":"0",
"failed_at":"0",
"received_at":"0",
"error":"None",
"created_at":"1414624856",
"contact":{
"id":"14",
"name":"Phyllis Turner",
"number":"+447791064713"
}
}
],
"fails":[
]
}
}
+3
source to share