多维数组
多维数组是包含一个或多个数组的数组
创建一个多维数组
$sites = array ( "runoob"=>array ( "php教程", "http://www.runoob.com" ), "google"=>array ( "Google 搜索", "http://www.google.com" ), "taobao"=>array ( "淘宝", "http://www.taobao.com" ) ); print("<pre>"); // 格式化输出数组 print_r($sites); print("</pre>");
格式化输出结果
Array ( [runoob] => Array( [0] => php教程 [1] => http://www.runoob.com ) [google] => Array( [0] => google 搜索 [1] => http://www.google.com ) [taobao] => Array( [0] => 淘宝 [1] => http://www.taobao.com ) )
输出数组
//根据格式化输出结果,输出某个值 echo $sites['runboob'][0] //php教程 echo $sites['runboob'][1] //http://www.runoob.com //数组循环 foreach($Array as $val){ echo $val; } foreach($Array as $key => $val){ echo $key.":".$val; }