Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

____foreach loop an multi-diminisional array?_____

Status
Not open for further replies.

Lynux

MIS
Aug 3, 2001
33
US
I am trying to loop through a multi-diminsional array
and having a little problems.
====================================================
Example array :
$rub[1][1][5] = 50.1
$rub[1][2][6] = 52.5
$rub[1][3][7] = 54.3
===========================================
Example code looping through to get keys and value:
foreach($rub[1] as $k2){
foreach($k2 as $k3 => $value){
echo $k2.&quot;-&quot;.$k3.&quot;-&quot;.$value.&quot;<br>&quot;;
}
}
===========================================
Example ouptput I am getting:
Array-5-50.1
Array-6-52.5
Array-7-54.3
===========================================
What I expected to get:
1-5-50.1
2-6-52.5
3-7-54.3
===========================================
Any ideas what I am doing wrong here??

Thanks in advance ! ! !
:)
=================================
Imagination is more important than knowledge.
(A.E.)
 
The output is correct. $k2 is an array. Or, more precisely, a succession of arrays which are the values stored in $rub[1].

Try this:

foreach($rub[1] as $k1 => $value1)
{
foreach($value1 as $k2 => $value2)
{
echo $k1.&quot;-&quot;.$k2.&quot;-&quot;.$value2.&quot;<br>&quot;;
}
} ______________________________________________________________________
Never forget that we are
made of the stuff of stars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top