PHP数组学习(二)

多维数组,也就是value为数组类型的情况,形式如下:

$array_name = array
(
	key1 => array
	(
		key11 =>value11,
		key12 =>value12,
		...
		key1n =>value1n,
	),
	key2 => array
	(
		key21 =>value21,
		key22 =>value22,
		...
		key2n =>value2n,
	),
	...
	keyn => array
	(
		keyn1 =>valuen1,
		keyn2 =>valuen2,
		...
		keynn =>valuenn,
	)
);

情形一:key为整型,

$test= array
(
0=>array(0,1,2),
1=>array(10,11,12),
2=>array(20,21,22)
);
//等价于
$test= array
(
array(0,1,2),
array(10,11,12),
array(20,21,22)
);
//简写
$test= array(array(0,1,2),array(10,11,12),array(20,21,22));

情形二:key为字符串,

$families = array
(
	"Ann" => array
		(
			"father" =>"Ann'father",
			 "mother" =>"Ann'mother",
			 "self" => "Ann"
		),
	"Blue" =>array
		( 
			"father" => "Blue'father",
			"mother" => "Blue'mother",
			"self" => "Blue"
		),
	"Joe" =>array
		( 
			"father" => "Joe'father",
			"mother" => "Joe'mother",
			"self" => "Joe"
		)
);
echo $families['Ann']['father']; // 输出 Ann'father

结束……

你可能感兴趣的:(PHP数组学习(二))