Valor McKinney Valor McKinney - 1 year ago 77
JSON Question

Getting Array Values Php

I have this coding that outputs a var_dump as:

object(stdClass)#1509 (9) {
string(7) "success"
string(30) "License key details retrieved."
string(6) "active"
string(1) "2"
string(22) ""
array(1) {
object(stdClass)#1984 (5) {
string(1) "5"
string(2) "14"
string(29) "G1.C-LicenseKey:LicenseKeyNumber"
string(8) ""
string(13) "My WP+ Portal"
string(10) "2016-11-10"
string(10) "0000-00-00"
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download