Introduction au...SE CONNECTER

Introduction aux tableaux multidimensionnels pour débutants PHP

php Tableau multidimensionnel

Les valeurs d'un tableau peuvent être un autre tableau, et la valeur d'un autre tableau peut également être un tableau. De cette façon, nous pouvons créer un tableau bidimensionnel ou tridimensionnel :

Créer un tableau bidimensionnel

Format :

tableau (

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

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

)

Exemple 1 :

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

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

Exemple 2 : Créer un tableau multidimensionnel

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

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

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

Un tableau multidimensionnel est un tableau contenant un ou plusieurs tableaux.

Dans les tableaux multidimensionnels, chaque élément du tableau principal peut également être un tableau, et chaque élément du sous-tableau peut également être un tableau


section suivante
<?php echo "hello world"; ?>
soumettreRéinitialiser le code
chapitredidacticiel