PHP有很多内置全局变量,例如$_SERVER,$_POST等,本文采用将关联数组嵌套到普通数组内进行打印。
方法1:
<?php $array=array($_SERVER,$_GET,$_POST,$_FILES,$_COOKIE,$_SESSION,$_REQUEST,$_ENV); foreach($array as $subarray) { foreach($subarray as $key => $value) { echo "key => ".$key." ,value => ".$value; echo "<br>"; } echo "<br><br>----------------------------------------------------------<br>"; } ?>
输出:
---------------------------------------------------------------------------------------------------------------------------------------
方法2:
<?php $array=array($_SERVER,$_GET,$_POST,$_FILES,$_COOKIE,$_SESSION,$_REQUEST,$_ENV); for($i=0;$i<count($array);$i++) { foreach($array[$i] as $key => $value) { echo "key => ".$key." ,value => ".$value; echo "<br>"; } echo "<br><br>----------------------------------------------------------<br>"; } ?>
输出同上。
通过两个小程序,加深对关联数组、循环、以及数组的嵌套理解。
标签:内置,数组,打印,value,echo,key,PHP From: https://www.cnblogs.com/codeprojects/p/18033070