qmqmqm Posted March 3, 2009 Share Posted March 3, 2009 Hi I know that for a 2d array when you iterate through it, you can go: foreach( $employeeAges as $key => $value){ echo "Name: $key, Age: $value <br />"; } but I have a 3 d array. Can I use: foreach( $employeeAges as $key => $value1 => value2){ echo "Name: $key, Age: $value1, $value2 <br />"; } How should I iterate through the array then? Thanks, Tom Link to comment https://forums.phpfreaks.com/topic/147732-3d-php-array/ Share on other sites More sharing options...
Mchl Posted March 3, 2009 Share Posted March 3, 2009 foreach ($employeeAges as $key => $value1) { foreach ($value1 as $key1 => $value2) { //do something } } Link to comment https://forums.phpfreaks.com/topic/147732-3d-php-array/#findComment-775515 Share on other sites More sharing options...
qmqmqm Posted March 3, 2009 Author Share Posted March 3, 2009 Thank you Mchl! Link to comment https://forums.phpfreaks.com/topic/147732-3d-php-array/#findComment-775532 Share on other sites More sharing options...
Mchl Posted March 3, 2009 Share Posted March 3, 2009 Just to clarify: it is actually a 2D array. For a 3D array you would need another loop Link to comment https://forums.phpfreaks.com/topic/147732-3d-php-array/#findComment-775676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.