0

所以基本上我想要的是用foreach显示一些变量,但它需要用嵌套循环来完成,因为它有子菜单。

这是列表:

<whmcsapi>
 <action>getclientsdomains</action>
 <clientid>123</clientid>
 <totalresults>2</totalresults>
 <startnumber>0</startnumber>
 <numreturned>2</numreturned>
 <domains>
 <domain>
  <id>1</id>
  <userid>123</userid>
  <orderid>1</orderid>
  <regtype>Register</regtype>
  <domainname>whmcsdomain.com</domainname>
  <registrar>enom</registrar>
  <regperiod>1</regperiod>
  <firstpaymentamount>8.95</firstpaymentamount>
  <recurringamount>8.95</recurringamount>
  <paymentmethod>paypal</paymentmethod>
  <paymentmethodname>Credit Card or Debit Card</paymentmethodname>
  <regdate>2011-01-01</regdate>
  <expirydate>2012-01-01</expirydate>
  <nextduedate>2012-01-01</nextduedate>
  <status>Active</status>
  <subscriptionid></subscriptionid>
  <dnsmanagement></dnsmanagement>
  <emailforwarding></emailforwarding>
  <idprotection></idprotection>
  <donotrenew></donotrenew>
  <notes></notes>
 </domain>
 ...
 </domains>
</whmcsapi>

是第一类第二类。

这是我迄今为止取得的成就,但没有结果:

    $command = 'getclientsdomains';
 $values = array('clientid' => $_SESSION['uid']);

 # Call API
 $results = localAPI($command,$values);

    foreach ($results as $id => $result) {

            echo $id . " " . $result ."<br />";

            foreach ($result as $domains) {

            echo $domains;

            foreach($domains as $key => $value) {

            echo $key . $value;

            }

            }

        }

这是输出:

result success
clientid 1
domainid 
totalresults 1
startnumber 0
numreturned 1
domains Array
Array

提前致谢。

4

1 回答 1

0

使用递归函数循环遍历数据

function print_list($node) {
    foreach($node as $key => $value) {
         if(is_array($value)) 
             print_list($value);
         else
             echo "$key: $value\n";
    }
}
于 2012-03-08T23:29:45.650 回答