Php cyclic output two-dimensional array and associative array

// define a two-dimensional array 
$ Products = Array ( 
    Array ( 'the TIR', 'Tires', 100), 
    Array ( 'OIL', 'Oil', 10), 
    Array ( 'SPK', 'the Spark Plugs',. 4) 
); 
// nested two-dimensional array for output support 
for ($ Row = 0; $ Row <. 3; $ Row ++) { 
    for ($ COL = 0; $ COL <. 3; $ COL ++) { 
        echo $ Products [$ Row ] [COL $] 'a';. 
    } 
} 
echo 'a'; 

// defined in associative array 
$ Products = array ( 
        array ( 
                'Code' => 'the TIR', 
                'the Description' => ' Tires ', 
                ' Prices '=> 100 
        ), 
        Array ( 
                ' Code '=>'OIL',
                'Description'=>'Oil',
                'Prices'=>10
        ),
        array(
                'Code'=>'SPK',
                'Description'=>'Spark Plugs',
                'Prices'=>4
        )
);

//关联数组不支持for嵌套循环
//echo var_dump($products);

echo '<br/>';
for($row=0;$row<3;$row++){
    foreach ($products[$row] as $key=>$value){
        echo $key.' - '.$value.'<br/>';
    }
}
echo '<br/>';

  

Guess you like

Origin www.cnblogs.com/wybing/p/11494688.html