1

I've opened before a question about name.com API and got helpful answers.

Now, I come again with another question, Question is about listing domain names:

I want to get the info out of multidimensional arrays, What I've done so far is this:

$api = new NameComApi();
$api->username('XXX');
$api->apiToken('XXXXXXXXX');
$response = $api->list_domains();

foreach($response->domains as $Domains){
    echo "<ul>"
    ."<li>Creation date = {$Domains->create_date}"
    ."<li>Expiring date = {$Domains->expire_date}"
    ."</ul>";
}

This was successful, But what I wasn't successful in is to get the domain name :(

You can find the array below:

stdClass Object
(
    [result] => stdClass Object
        (
            [code] => 100
            [message] => Command Successful
        )

    [domains] => stdClass Object
        (
            [XXXXXXX.com] => stdClass Object
                (
                    [tld] => com
                    [create_date] => 2007-08-21 19:37:59
                    [expire_date] => 2013-08-22 01:37:59
                    [addons] => stdClass Object
                        (
                            [whois_privacy] => stdClass Object
                                (
                                    [price] => 3.99
                                )

                            [domain/renew] => stdClass Object
                                (
                                    [price] => 10.99
                                )

                        )

                )

What I've been tried to far:

$Domains->domains
$Domains->domains[1]
$Domains->domains[]

But no luck, I know that I'm missing something important but I don't know what it is.

Waiting your reply.

Thanks in advance.

1 Answer 1

1
var_dump(array_keys((array) $response->domains));

Or (because you iterate over the result anyway

foreach((array) $response->domains as $name => $domain) { /* code */ }
Sign up to request clarification or add additional context in comments.

10 Comments

Done! Thank you. Full code: foreach($response->domains as $name => $Domains){ echo "<ul>" ."<li>Domain Name = {$name}" ."<li>Creation date = {$Domains->create_date}" ."<li>Expiring date = {$Domains->expire_date}" ."</ul>"; } Why is that? Could you please explain?
Another question please if you don't mind: I can't get the price out of this array [domain/renew] because of the '/' How can I fix it?
See php.net/control-structures.foreach. When you cast an object to an array PHP will take the properties as the keys of the (associative) array. foreach with an object automatically casts it to an array. // $foo = (array) $bar; echo $bar['domain/renew'); Would be easier, the API would return arrays instead of objects ...
Error: {$Domains->addons->['domain/renew']}
I've read it, You see the array? I want to get out the price from it, Price is inside the addons array that inside the domains array
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.