Access array data in foreach?

This is a discussion on Access array data in foreach? within the PHP General forums, part of the PHP Programming Forums category; Hello, I Have an array $toplevel containing arrays: Array ( [0] => Array ( [0] => 1 [1] => 1 [2] => ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2007
William Stokes
 
Posts: n/a
Default Access array data in foreach?

Hello,

I Have an array $toplevel containing arrays:
Array (

[0] => Array (
[0] => 1
[1] => 1
[2] => eka
[3] => eka.php )

[1] => Array (
[0] => 2
[1] => 1
[2] => toka
[3] => toka.php )

[2] => Array (
[0] => 3
[1] => 1
[2] => kolmaz
[3] => kolmas.php )

[3] => Array (
[0] => 4
[1] => 1
[2] => nepa
[3] => nepa.php )

)

How access the data in foreach? Now I do this and it prints Array[2] to
screenin every loop.

foreach ($toplevel as $value){
print "myTest.addLabel('labelBullet', '$toplevel[2][2]', $TopLevelCounter+1,
250, '#CC0000', '#0000aa', '$toplevel[3]', 'left');\n";
$TopLevelCounter ++;
}

But
print $toplevel[2][2]

outside foreach prints kolmaz like I suppose it should

Thanks again
-Will
Reply With Quote
  #2 (permalink)  
Old 01-06-2007
Casey Chu
 
Posts: n/a
Default Re: [PHP] Access array data in foreach?

$value holds the value of the current array element.

On 1/6/07, William Stokes <kalles@operamail.com> wrote:
> Hello,
>
> I Have an array $toplevel containing arrays:
> Array (
>
> [0] => Array (
> [0] => 1
> [1] => 1
> [2] => eka
> [3] => eka.php )
>
> [1] => Array (
> [0] => 2
> [1] => 1
> [2] => toka
> [3] => toka.php )
>
> [2] => Array (
> [0] => 3
> [1] => 1
> [2] => kolmaz
> [3] => kolmas.php )
>
> [3] => Array (
> [0] => 4
> [1] => 1
> [2] => nepa
> [3] => nepa.php )
>
> )
>
> How access the data in foreach? Now I do this and it prints Array[2] to
> screenin every loop.
>
> foreach ($toplevel as $value){
> print "myTest.addLabel('labelBullet', '$toplevel[2][2]', $TopLevelCounter+1,
> 250, '#CC0000', '#0000aa', '$toplevel[3]', 'left');\n";
> $TopLevelCounter ++;
> }
>
> But
> print $toplevel[2][2]
>
> outside foreach prints kolmaz like I suppose it should
>
> Thanks again
> -Will
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply With Quote
  #3 (permalink)  
Old 01-06-2007
William Stokes
 
Posts: n/a
Default Re: [PHP] Access array data in foreach?

Uh. (Embarrassed)

Thanks anyway!!

-W
""Casey Chu"" <heavyccasey@gmail.com> kirjoitti
viestissä:1a221fe0701060900s4f360981v5b3ece8bd6604 ec3@mail.gmail.com...
> $value holds the value of the current array element.
>
> On 1/6/07, William Stokes <kalles@operamail.com> wrote:
>> Hello,
>>
>> I Have an array $toplevel containing arrays:
>> Array (
>>
>> [0] => Array (
>> [0] => 1
>> [1] => 1
>> [2] => eka
>> [3] => eka.php )
>>
>> [1] => Array (
>> [0] => 2
>> [1] => 1
>> [2] => toka
>> [3] => toka.php )
>>
>> [2] => Array (
>> [0] => 3
>> [1] => 1
>> [2] => kolmaz
>> [3] => kolmas.php )
>>
>> [3] => Array (
>> [0] => 4
>> [1] => 1
>> [2] => nepa
>> [3] => nepa.php )
>>
>> )
>>
>> How access the data in foreach? Now I do this and it prints Array[2] to
>> screenin every loop.
>>
>> foreach ($toplevel as $value){
>> print "myTest.addLabel('labelBullet', '$toplevel[2][2]',
>> $TopLevelCounter+1,
>> 250, '#CC0000', '#0000aa', '$toplevel[3]', 'left');\n";
>> $TopLevelCounter ++;
>> }
>>
>> But
>> print $toplevel[2][2]
>>
>> outside foreach prints kolmaz like I suppose it should
>>
>> Thanks again
>> -Will
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

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 09:59 PM.


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