array  (  "Peter",  "Lois",  "Megan"  ),  "Quagmire"="/> array  (  "Peter",  "Lois",  "Megan"  ),  "Quagmire"=">
Home > Backend Development > PHP Tutorial > php 多维数组小疑点

php 多维数组小疑点

WBOY
Release: 2016-06-13 11:11:34
Original
1020 people have browsed it

php 多维数组小问题

$families = array<br />(<br />  "Griffin"=>array<br />  (<br />  "Peter",<br />  "Lois",<br />  "Megan"<br />  ),<br />  "Quagmire"=>array<br />  (<br />  "Glenn"<br />  ),<br />  "Brown"=>array<br />  (<br />  "Cleveland",<br />  "Loretta",<br />  "Junior"<br />  )<br />);
Copy after login


正常打印一个元素的话,是这么写
$families[Griffin][0],
可是我见到了这么写的
$families[Griffin[0]],
请问有什么不同,分别用在什么场所啊


------解决方案--------------------
<br />//正如#1和#2楼所说对于楼主的例子来说第二个写法确实存在问题<br />//如果你实在想要一个值不妨改一下数组<br />	$families = array<br />(<br />  "Griffin"=>array<br />  (<br />  "Peter",<br />  "Lois",<br />  "Megan"<br />  ),<br />  "Quagmire"=>array<br />  (<br />  "Glenn"<br />  ),<br />  "Brown"=>array<br />  (<br />  "Cleveland",<br />  "Loretta",<br />  "Junior"<br />  ),<br />  "Peter"=>9<br />);<br />  $Griffin=array(<br />  "Peter",<br />  "Lois",<br />  "Megan"<br />  );<br />print_r($families['Griffin'][0]);<br />print_r($Griffin[0]);<br />print_r($families[$Griffin[0]]);<br />
Copy after login

------解决方案--------------------
<br />//将名为fmilies数组的 下标值为[Griffin],[0]取出<br />$families[Griffin][0],<br />//将名为fmilies数组的 下标值为[Griffin[0]]取出<br />$families[Griffin[0]],<br />
Copy after login

两种写法意义不同[]中的值就是数组中的下表
这个例子中第二种写法是错误的
------解决方案--------------------
第2中写法意思玩去昂不跟第一种相同

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template