two dimensional arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gammaman
Forum Commoner
Posts: 45
Joined: Tue Feb 12, 2008 9:22 am

two dimensional arrays

Post by gammaman »

I am new to programming and was need help. Can someone please give me an example
of how to use a foreach loop to go through the indexes of a two dimensional array.
User avatar
webspider
Forum Commoner
Posts: 52
Joined: Sat Oct 27, 2007 3:29 am

Re: two dimensional arrays

Post by webspider »

Code: Select all

 
$a = array();
$a[0][0] = "a";
$a[0][1] = "b";
$a[1][0] = "y";
$a[1][1] = "z";
 
foreach ($a as $index1=>$value1) {
    foreach ($value1 as $index2=>$value2) {
        echo "index1 = $index1 <br />";    
        echo "index2 = $index2 <br />";
    }
}
 
 
 
gammaman
Forum Commoner
Posts: 45
Joined: Tue Feb 12, 2008 9:22 am

Re: two dimensional arrays

Post by gammaman »

Thank you, that helps a lot :D
Post Reply