Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-07-2011, 07:15 PM   #1
New Member
 
Join Date: Jun 2011
Posts: 9
Smile PHP Arrays help

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
__________________
website designers

Last edited by shingionline; 12-07-2011 at 07:25 PM.
shingionline is offline   Reply With Quote


Old 12-07-2011, 07:53 PM   #2
Gold Member
 
Join Date: Feb 2011
Location: Australia
Posts: 369
Default

I believe you are looking for the foreach loop
__________________
Jason H.
DHDdirect.com
Domains - Hosting - Design
DHDdirect is offline   Reply With Quote
Old 12-07-2011, 08:18 PM   #3
New Member
 
Join Date: Jun 2011
Posts: 9
Default

Quote:
Originally Posted by DHDdirect View Post
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'];
__________________
website designers
shingionline is offline   Reply With Quote
Old 12-08-2011, 11:52 AM   #4
Silver Member
 
Join Date: Aug 2011
Posts: 100
Default

Quote:
Originally Posted by shingionline View Post
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 Code:
[PRODUCTS] => Array
                (
                    [
PRODUCT] => Array()
                ) 
Products is inside product so you would need:

PHP Code:
$arr['WHMCSAPI']['PRODUCTS']['PRODUCT']['USERNAME']; 
__________________
Mark R

Wubbleyou - Web Design Newcastle
A professional web design agency based in Newcastle upon Tyne servicing clients based throughout the U.K.

Home spray tan machine - Landlord Reviews
MarkR is offline   Reply With Quote
Old 12-08-2011, 12:12 PM   #5
New Member
 
Join Date: Jun 2011
Posts: 9
Default

Works perfectly, thanks Mark
__________________
website designers
shingionline is offline   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:34 AM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.