inspireddesign Posted November 26, 2010 Share Posted November 26, 2010 Hello All!! I have the following array: How would I extract the values in the this array using a foreach loop? Thanks!! QuickBooks_Object_Customer Object ( [_object:protected] => Array ( [ListID] => 284 [TimeCreated] => 2010-11-23T13:09:22 [TimeModified] => 2010-11-26T10:07:47 [EditSequence] => 2 [Name] => Keith Palmer (1417262473) [FullName] => Keith Palmer (1417262473) [sublevel] => 0 [CompanyName] => New Company Name [FirstName] => Damian [LastName] => Clem [shipAddress Addr1] => 134 Stonemill Road [shipAddress City] => Storrs [shipAddress State] => CT [shipAddress PostalCode] => 06268 [PrintAs] => Keith Palmer (1417262473) [balance] => 0.00 [TotalBalance] => 0.00 [isStatementWithParent] => false [DeliveryMethod] => Print ) ) Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/ Share on other sites More sharing options...
inspireddesign Posted November 26, 2010 Author Share Posted November 26, 2010 The array from print_r($Customer); QuickBooks_Object_Customer Object ( [_object:protected] => Array ( [ListID] => 284 [TimeCreated] => 2010-11-23T13:09:22 [TimeModified] => 2010-11-26T10:07:47 [EditSequence] => 2 [Name] => Keith Palmer (1417262473) [FullName] => Keith Palmer (1417262473) [sublevel] => 0 [CompanyName] => New Company Name [FirstName] => Damian [LastName] => Clem [shipAddress Addr1] => 134 Stonemill Road [shipAddress City] => Storrs [shipAddress State] => CT [shipAddress PostalCode] => 06268 [PrintAs] => Keith Palmer (1417262473) [balance] => 0.00 [TotalBalance] => 0.00 [isStatementWithParent] => false [DeliveryMethod] => Print ) ) Here is what I have so far but there's no output. Doesn't throw any errors. Thanks for any help you can provide me. $Customer = $API->getCustomerByName('Keith Palmer (1417262473)'); // Generates the Array I want to loop through. foreach ( $Customer as $cust => $value ) { echo $cust['ListID'][$value]; } Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140069 Share on other sites More sharing options...
The Little Guy Posted November 26, 2010 Share Posted November 26, 2010 Try this: $Customer = $API->getCustomerByName('Keith Palmer (1417262473)'); // Generates the Array I want to loop through. foreach ( $Customer as $cust => $value ) { echo $cust->ListID[$value]; } Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140076 Share on other sites More sharing options...
requinix Posted November 26, 2010 Share Posted November 26, 2010 An array? You think it's an array? Look at the output from print_r. QuickBooks_Object_Customer Object ( What do you see in there that indicates it's an array? You cannot access the information by normal means, according to that output. Since being totally inaccessible would be stupid, there's likely another way. Try echo $Customer->ListID; Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140077 Share on other sites More sharing options...
The Little Guy Posted November 26, 2010 Share Posted November 26, 2010 An array? You think it's an array? Look at the output from print_r. QuickBooks_Object_Customer Object ( What do you see in there that indicates it's an array? You cannot access the information by normal means, according to that output. Since being totally inaccessible would be stupid, there's likely another way. Try echo $Customer->ListID; you can still access them from a foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140081 Share on other sites More sharing options...
inspireddesign Posted November 26, 2010 Author Share Posted November 26, 2010 I tried both approaches and neither worked guys ;( I know I can get a this data LOL! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140084 Share on other sites More sharing options...
jcbones Posted November 27, 2010 Share Posted November 27, 2010 QuickBooks_Object_Customer Object ( [_object:protected] I thought protected variables could not be used or modified outside of the parent/child classes that control it. Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140206 Share on other sites More sharing options...
requinix Posted November 27, 2010 Share Posted November 27, 2010 QuickBooks_Object_Customer Object ( [_object:protected] I thought protected variables could not be used or modified outside of the parent/child classes that control it. That's right... Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140215 Share on other sites More sharing options...
inspireddesign Posted November 28, 2010 Author Share Posted November 28, 2010 Thanks for the help so far everyone. Here's what I have right now as my output. This is NOT protected by any class. How would I extract this information using a foreach loop? This is what I'm doing now and I'm only getting the first character in the loop. Moreover, It's looping though the entire array printing everything and not what I've indicated in the loop. Not sure why? Thanks for any help on this! Array ( [ListID] => 284 [TimeCreated] => 2010-11-23T13:09:22 [TimeModified] => 2010-11-26T10:07:47 [EditSequence] => 2 [Name] => Keith Palmer (1417262473) [FullName] => Keith Palmer (1417262473) [sublevel] => 0 [CompanyName] => New Company Name [FirstName] => Damian [LastName] => Clem [shipAddress Addr1] => 134 Stonemill Road [shipAddress City] => Storrs [shipAddress State] => CT [shipAddress PostalCode] => 06268 [PrintAs] => Keith Palmer (1417262473) [balance] => 1.00 [TotalBalance] => 1.00 [isStatementWithParent] => false [DeliveryMethod] => Print ) $custInfo = $API->getCustomerByName('Keith Palmer (1417262473)'); $custInfoArry = $custInfo->asList(QUICKBOOKS_ADD_CUSTOMER); foreach ( $custInfoArry as $Customer ) { echo 'ListID: ' . $Customer['ListID'] . '<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140463 Share on other sites More sharing options...
inspireddesign Posted November 28, 2010 Author Share Posted November 28, 2010 I guess I don't need a foreach loop here ... this is what I've done to extract the data. echo $custInfoArry['ListID'] Quote Link to comment https://forums.phpfreaks.com/topic/219932-array-help/#findComment-1140469 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.