Valor McKinney Valor McKinney - 26 days ago 15
JSON Question

Getting Array Values Php

I have this coding that outputs a var_dump as:

object(stdClass)#1509 (9) {
["result"]=>
string(7) "success"
["message"]=>
string(30) "License key details retrieved."
["status"]=>
string(6) "active"
["max_allowed_domains"]=>
string(1) "2"
["email"]=>
string(22) "email@icloud.com"
["registered_domains"]=>
array(1) {
[0]=>
object(stdClass)#1984 (5) {
["id"]=>
string(1) "5"
["lic_key_id"]=>
string(2) "14"
["lic_key"]=>
string(29) "G1.C-LicenseKey:LicenseKeyNumber"
["registered_domain"]=>
string(8) "domain.com"
["item_reference"]=>
string(13) "My WP+ Portal"
}
}
["date_created"]=>
string(10) "2016-11-10"
["date_renewed"]=>
string(10) "0000-00-00"
["date_expiry"]=>
string(10) "0000-00-00"
}


I'm using PHP and my coding is as follows:

// prepare the data
$data = array ();
$data['secret_key'] = $secretKeky;
$data['slm_action'] = 'slm_check';
$data['email'] = $email;
$data['license_key'] = $options['G2SETAPI_lic_2'];

// send data to post URL
$ch = curl_init ($postURL);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returnValue = curl_exec ($ch);


$license_data = json_decode(($returnValue));

// TODO - Do something with it.
var_dump($license_data); //uncomment it to look at the data


I'm currently trying to get the "lic_key" value. Here's the coding I have.

echo '<br />The following license key '.$license_data->registered_domains->lic_key.' was returned from the server as '.$license_data->status.'';


How can I get the lic_key under the registered_domains array?

Answer

Try with $license_data->registered_domains[0]->lic_key?