Hertus Hertus - 1 year ago 50
PHP Question

Get specific key out of an array

I have this array:

$client = new OAuth2\Client($client_id, $client_secret, $region, $locale, $redirect_uri);

$array = array('id'=>'13146');
$type = 'quest';
$r = $client->fetch($type,$array);
echo '<pre>';
print_r ($r);
echo '</pre>';


The output:

[result] => Array
[id] => 13146
[title] => Generosity Abounds
[reqLevel] => 77
[suggestedPartyMembers] => 0
[category] => Icecrown
[level] => 80

I just want to read out the [title] and the [category]. I´ve tried a a couple of solutions but nothing works for me. Thanks.

Answer Source

To access title and category you need to do this:

echo $r['result']['title'];    // Generosity Abounds
echo $r['result']['category']; // Icecrown