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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi dmiensional arrray 1

Status
Not open for further replies.

JimFL

Programmer
Jun 17, 2005
131
GB
Hi,

I would like to know if anybody has a good solution for working through a multidimensional array and retrieving information for just one of the keys. For example I have an array that is built like this

for ($i=0;$i<5;$i++){
$array[$cnt]['x'] = $i;
$array[$cnt]['y'] = $i;
$array[$cnt]['z'] = $i;
}

essentially I am not worried about the data in the array just want to be able to do something when I iterate through the array only when I am at index $array[$cnt]['x'];

foreach( $array as $key => $value){
foreach ($value as $k){
??how do I reference value $i at only the x
}
}

is there a array method to test whether I have got the x component? I have tried to use the $value parameter but it gives me an array

Any ideas?

 
I think I may just want to use the first for loop. ie.

foreach( $array as $key => $value){
??how do I reference value the x value for each
}


 
Thanks for that.
Also just found another solution myself.

foreach( $array as $key => $value){
$array[$key]['x']; //give me the point
}




 
or
Code:
for ($i=0; $i<count($array);$i++):
 echo $array[$i]['x'];
endfor;

or you can of course reference an element directly at any time
echo $array[1]['x']
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top