PHP Beginner's Introduction to Multidimensional Arrays

php Multidimensional array

The value in one array can be another array, and the value of another array can also be an array. In this way, we can create a two-dimensional or three-dimensional array:

Create a two-dimensional array

Format:

array(

array(1,2,3,4,5),

array(6,7,8,9,10)

)

Example 1:

<?php
	$arr = array(
			array(1,2,3,4,5),
			array(6,7,8,9,10)
		);

	echo "<pre>";
	print_r($arr);
	echo "</pre>";
?>

Example 2: Create a multidimensional array

<?php 
header("Content-type: text/html; charset=utf-8");//设置编码 
$sites = array ( 
        "php"=>array ( 
            "php中文网", 
            "//m.sbmmt.com" 
        ), 

        "google"=>array ( 
            "Google 搜索", 
            "http://www.google.com" 
        ), 

        "taobao"=>array( 
            "淘宝", 
            "http://www.taobao.com" 
        ) 
); 
print("<pre>"); // 格式化输出数组 
print_r($sites); 
print("</pre>"); 
?>

A multidimensional array is an array containing one or more arrays.

In a multi-dimensional array, each element in the main array can also be an array, and each element in the sub-array can also be an array


Continuing Learning
||
<?php echo "hello world"; ?>
submitReset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!