printing out this nested array

This is a discussion on printing out this nested array within the PHP General forums, part of the PHP Programming Forums category; I am having a bit of a confusion printing the values of an array i have. When i print_r this ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2007
Don Don
 
Posts: n/a
Default printing out this nested array

I am having a bit of a confusion printing the values of an array i have. When i print_r this array it contains the following:

Array ( [ValueA] => ValueA [ValueB] => valueB [TestValue] => TestValue [Errors] => Array ( [0] => Array ( [ErrorId] => AD27JH [ErrorMsg] => OK ) ) )
I can get the values of ValueA, ValueB and TestValue but I am a bit confused at getting the values of ErrorId and ErrorMsg.

e.g. echo $arrayName['ValueA']; // will display the value contained there

am thinking echo $arrayName['Errors']['ErrorId']; // should display the value but it does not
Anyone wants to shed more light ?

Cheers



---------------------------------
8:00? 8:25? 8:40? Find a flick in no time
with theYahoo! Search movie showtime shortcut.
Reply With Quote
  #2 (permalink)  
Old 05-14-2007
Crayon Shin Chan
 
Posts: n/a
Default Re: [PHP] printing out this nested array

On Monday 14 May 2007 18:41, Don Don wrote:

> am thinking echo $arrayName['Errors']['ErrorId']; // should display the
> value but it does not Anyone wants to shed more light ?


echo $arrayName['Errors'][0]['ErrorId']; // ??

--
Crayon
Reply With Quote
  #3 (permalink)  
Old 05-14-2007
Richard Davey
 
Posts: n/a
Default Re: [PHP] printing out this nested array

Don Don wrote:

> I am having a bit of a confusion printing the values of an array i have. When i print_r this array it contains the following:
>
> Array ( [ValueA] => ValueA [ValueB] => valueB [TestValue] => TestValue [Errors] => Array ( [0] => Array ( [ErrorId] => AD27JH [ErrorMsg] => OK ) ) )
> I can get the values of ValueA, ValueB and TestValue but I am a bit confused at getting the values of ErrorId and ErrorMsg.
>
> e.g. echo $arrayName['ValueA']; // will display the value contained there
>
> am thinking echo $arrayName['Errors']['ErrorId']; // should display the value but it does not
> Anyone wants to shed more light ?


$arrayName['Errors'][0]['ErrorId']

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"
Reply With Quote
  #4 (permalink)  
Old 05-14-2007
Don Don
 
Posts: n/a
Default Re: [PHP] printing out this nested array

oops ! [0]

cheers

Richard Davey <rich@corephp.co.uk> wrote:
Don Don wrote:

> I am having a bit of a confusion printing the values of an array i have. When i print_r this array it contains the following:
>
> Array ( [ValueA] => ValueA [ValueB] => valueB [TestValue] => TestValue [Errors] => Array ( [0] => Array ( [ErrorId] => AD27JH [ErrorMsg] => OK ) ) )
> I can get the values of ValueA, ValueB and TestValue but I am a bit confused at getting the values of ErrorId and ErrorMsg.
>
> e.g. echo $arrayName['ValueA']; // will display the value contained there
>
> am thinking echo $arrayName['Errors']['ErrorId']; // should display the value but it does not
> Anyone wants to shed more light ?


$arrayName['Errors'][0]['ErrorId']

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




---------------------------------
Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search.
Reply With Quote
  #5 (permalink)  
Old 05-14-2007
Brad Fuller
 
Posts: n/a
Default RE: [PHP] printing out this nested array

Don Don wrote:
> I am having a bit of a confusion printing the values of an
> array i have. When i print_r this array it contains the following:
>
> Array ( [ValueA] => ValueA [ValueB] => valueB [TestValue] =>
> TestValue [Errors] => Array ( [0] => Array ( [ErrorId] =>
> AD27JH [ErrorMsg] => OK ) ) )
> I can get the values of ValueA, ValueB and TestValue but I
> am a bit confused at getting the values of ErrorId and ErrorMsg.
>
> e.g. echo $arrayName['ValueA']; // will display the value
> contained there
>
> am thinking echo $arrayName['Errors']['ErrorId']; // should
> display the value but it does not
> Anyone wants to shed more light ?
>
> Cheers


echo $arrayName['Errors'][0]['ErrorId'];

-B
Reply With Quote
  #6 (permalink)  
Old 05-14-2007
Jim Lucas
 
Posts: n/a
Default Re: [PHP] printing out this nested array

Don Don wrote:
> I am having a bit of a confusion printing the values of an array i have. When i print_r this array it contains the following:
>
> Array ( [ValueA] => ValueA [ValueB] => valueB [TestValue] => TestValue [Errors] => Array ( [0] => Array ( [ErrorId] => AD27JH [ErrorMsg] => OK ) ) )
> I can get the values of ValueA, ValueB and TestValue but I am a bit confused at getting the values of ErrorId and ErrorMsg.
>
> e.g. echo $arrayName['ValueA']; // will display the value contained there
>
> am thinking echo $arrayName['Errors']['ErrorId']; // should display the value but it does not
> Anyone wants to shed more light ?
>
> Cheers
>
>
>
> ---------------------------------
> 8:00? 8:25? 8:40? Find a flick in no time
> with theYahoo! Search movie showtime shortcut.

suggestion for next time. echo a <pre> or <plaintext> tag out before you echo your array next time
and you will then see the nesting of the arrays

Doing that would have made the answer to this question very obvious

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Unknown
Reply With Quote
  #7 (permalink)  
Old 05-14-2007
Myron Turner
 
Posts: n/a
Default Re: [PHP] printing out this nested array

> Jim Lucas wrote:--
>
>
> "Some men are born to greatness, some achieve greatness,
> and some have greatness thrust upon them."
>
> Unknown



Malvolio,12th Night, III.iv

--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/
Reply With Quote
  #8 (permalink)  
Old 05-14-2007
Richard Davey
 
Posts: n/a
Default Re: [PHP] printing out this nested array

Jim Lucas wrote:

> suggestion for next time. echo a <pre> or <plaintext> tag out before
> you echo your array next time and you will then see the nesting of the
> arrays
>
> Doing that would have made the answer to this question very obvious


You could also benefit from installing this very handy little bit of
code into your PHP project:

http://krumo.sourceforge.net/

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0