PHP Arrays help

shingionline

New Member
Hi Guys,

I have an array
Code:
$arr

When i run this function
Code:
print_r($arr)

I get the output below:-

--------------------------------

Code:
Array
(
    [WHMCSAPI] => Array
        (
            [ACTION] => getclientsproducts
            [RESULT] => success
            [CLIENTID] => 87
            [PID] => 13
            [DOMAIN] => dfgbhcgnd.com
            [TOTALRESULTS] => 1
            [STARTNUMBER] => 0
            [NUMRETURNED] => 1
            [PRODUCTS] => Array
                (
                    [PRODUCT] => Array
                        (
                            [ID] => 196
                            [CLIENTID] => 87
                            [ORDERID] => 218
                            [PID] => 13
                            [REGDATE] => 2011-12-07
                            [NAME] => Walderizer
                            [DOMAIN] => dfgbhcgnd.com
                            [DEDICATEDIP] => 
                            [SERVERID] => 3
                            [FIRSTPAYMENTAMOUNT] => 55.00
                            [RECURRINGAMOUNT] => 55.00
                            [PAYMENTMETHOD] => banktransfer
                            [PAYMENTMETHODNAME] => Bank Transfer
                            [BILLINGCYCLE] => Monthly
                            [NEXTDUEDATE] => 2011-12-07
                            [STATUS] => Active
                            [USERNAME] => vitaforiz
                            [PASSWORD] => ghTfg476fg
                            [SUBSCRIPTIONID] => 
                            [LASTUPDATE] => 0000-00-00 00:00:00
                            [CUSTOMFIELDS] => Array
                                (
                                    [CUSTOMFIELD] => Array
                                        (
                                            [NAME] => IP Address
                                            [VALUE] => 
                                        )

                                )

                            [CONFIGOPTIONS] => 

                        )

                )

        )

)

---------------------------------

My question is, how can i print only certain parts of the data rather than printing the whole array. For example i only want to echo the values for [NAME], [USERNAME], [PASSWORD] and [NEXTDUEDATE] from the [PRODUCT] part of the array

Thanks in advance
 
Last edited:

shingionline

New Member
I believe you are looking for the foreach loop

No i'm not looking for the foreach loop because i just want specific values. The following
Code:
echo $arr['WHMCSAPI']['DOMAIN'];
works well for the first level now i want to be able to output from the second level. The code below gives an error
Code:
$arr['WHMCSAPI']['PRODUCT']['USERNAME'];
 

MarkR

New Member
No i'm not looking for the foreach loop because i just want specific values. The following
Code:
echo $arr['WHMCSAPI']['DOMAIN'];
works well for the first level now i want to be able to output from the second level. The code below gives an error
Code:
$arr['WHMCSAPI']['PRODUCT']['USERNAME'];

It's because:


PHP:
[PRODUCTS] => Array
                (
                    [PRODUCT] => Array()
                )

Products is inside product so you would need:

PHP:
$arr['WHMCSAPI']['PRODUCTS']['PRODUCT']['USERNAME'];
 
Top