Iterating through a multidimensional array with for() : for loop « Statement « PHP






Iterating through a multidimensional array with for()

 
<?
$specials = array( array('A', 'A', 'B'),
                   array('C','W', 'P') );

for ($i = 0, $num_specials = count($specials); $i < $num_specials; $i++) {
    for ($m = 0, $num_sub = count($specials[$i]); $m < $num_sub; $m++) {
        print "Element [$i][$m] is " . $specials[$i][$m] . "\n";
    }
}
?>
  
  








Related examples in the same category

1.For statement without second condition
2.For statement without all three statements
3.For loop: Counting Backwards
4.For loop: Counting By Fives
5.Use for loop to output HTML table
6.For loop format
7.If statement inside a for loop
8.Nesting Two for Loops
9.A for Loop That Divides 4000 by Ten Incremental Numbers
10.Using the for Statement
11.A division table
12.A for Loop That Divides 4000 by Ten Incremental Numbers
13.A for loop in PHP
14.Alternating table row colors with for()
15.Loops Within Loops
16.Iterating through a numeric array with for()
17.Loop goes from 0 to 100 in steps of 0.1
18.Fahrenheit and Celsius table by for loop
19.Specifying a number after break, such as break 2, to break out of two loops or switch/case statements
20.Multiple expressions in for()
21.Nesting Two for Loops
22.Printing a
23.Printing out all the web-safe color codes