Really need some help with the following.
So, my script calls an API on remote server with:
try {
$api = new ApiClient();
$api->call('GetNameservers', $postfields);
return array(
'success' => true,
'ns1' => $api->getFromResponse('nameserver1'),
'ns2' => $api->getFromResponse('nameserver2'),
'ns3' => $api->getFromResponse('nameserver3'),
'ns4' => $api->getFromResponse('nameserver4'),
'ns5' => $api->getFromResponse('nameserver5'),
);
}
The above API call correctly returns what is must:
Array
(
[result] => 1000
[resData] => Array
(
[domain] => somecooldomain.com
[status] => Active
[autorenew] => 0
[contactid] => 822
[nameserver1] => ns1.nameserver1.com
[nameserver2] => ns2.nameserver2.com
[nameserver3] => ns3.nameserver3.com
[nameserver4] => ns4.nameserver4.com
[nameserver5] =>
[registrationdate] => 2018-06-29
[expirydate] => 2020-11-03
)
)
My problem comes after:
return array(
'success' => true,
This works:
'ns1' => $api->getFromResponse('result'),
But it is not what I need as the array is nested. I've tried many things here:
'ns1' => $api->getFromResponse('resData.nameserver1'),
'ns1' => $api->getFromResponse(['resData']['nameserver1']),
The getFromReponse is as follow:
public function getFromResponse($key)
{
return isset($this->results[$key]) ? $this->results[$key] : '';
}
$api['resData']['nameserver1']?var_dump($api->getFromResponse('result'), $api->getFromResponse('result')['resData']['nameserver1']);The first one will show the full structure. The second should return the expected entry from that structure