PHP tableau multidimensionnel
Un tableau de valeur peut être un autre tableau, une autre valeur de tableau peut aussi être un tableau. De cette manière, on peut créer un réseau bidimensionnel ou tridimensionnel:
Exemples
<?php
// 二维数组:
$cars = array
(
array("Volvo",100,96),
array("BMW",60,59),
array("Toyota",110,100)
);
?>
// 二维数组:
$cars = array
(
array("Volvo",100,96),
array("BMW",60,59),
array("Toyota",110,100)
);
?>
Exécution instance »
PHP - tableaux multidimensionnels
Tableau multidimensionnel contenant un ou plusieurs tableaux de tableaux.
Dans un tableau multidimensionnel réseau principal, chaque élément peut également être un tableau de sous-réseaux de chaque élément peut également être une matrice.
Exemples
Dans cet exemple, nous créons une clé d'identification assignés automatiquement tableau multidimensionnel:
Exemples
<? Php
$ Sites = array
(
"W3big" => array
(
"Tutorial"
"Http://www.w3big.com"
),
"Google" => array
(
"Recherche Google"
"Http://www.google.com"
),
"Taobao" => array
(
"Taobao"
"Http://www.taobao.com"
)
);
print ( "<pre>") ; // format de tableau de sortie
print_r (sites de $);
print ( "</ pre>" );
?>
$ Sites = array
(
"W3big" => array
(
"Tutorial"
"Http://www.w3big.com"
),
"Google" => array
(
"Recherche Google"
"Http://www.google.com"
),
"Taobao" => array
(
"Taobao"
"Http://www.taobao.com"
)
);
print ( "<pre>") ; // format de tableau de sortie
print_r (sites de $);
print ( "</ pre>" );
?>
La sortie du tableau ci-dessus comme suit:
exemple 2
Essayons de montrer une valeur dans le tableau ci-dessus:
echo $sites['w3big'][0] . '地址为:' . $sites['w3big'][1];
Le code ci-dessus va afficher: