Php 获取“的名称”;“父亲”;数组来自";“儿童”;
我希望能够从它的子数组中命名一个“父”数组,以便将所有发送到页面的HTTP变量写入调试文件。假设我有这个代码(并且该页面被远程调用): 我希望实现的是包含以下信息的调试文件:Php 获取“的名称”;“父亲”;数组来自";“儿童”;,php,multidimensional-array,Php,Multidimensional Array,我希望能够从它的子数组中命名一个“父”数组,以便将所有发送到页面的HTTP变量写入调试文件。假设我有这个代码(并且该页面被远程调用): 我希望实现的是包含以下信息的调试文件: getallheaders() -------------- Host : 1.2.3.4 Connection : keep-alive // all other members of getallheaders() array $_POST -------------- // assuming that page w
getallheaders()
--------------
Host : 1.2.3.4
Connection : keep-alive
// all other members of getallheaders() array
$_POST
--------------
// assuming that page was called via HTTP POST
INPUT1 : input one text
INPUT2 : input two text
// all other members of $_POST array
$_GET
--------------
// assuming that page was called via HTTP GET
INPUT10 : input ten text
INPUT11 : input eleven text
// all other members of $_GET array
...
等等
目前,我在调试文件中获得了我想要的所有信息,但我当前正在处理的父数组的“名称”只是显示为数组:这完全有道理,但我无法确定如何获取它的名称并将其显示为字符串值。以下是调试文件的内容:
Array
--------------
Host : 1.2.3.4
Connection : keep-alive
// all other members of getallheaders() array
Array
--------------
// assuming that page was called via HTTP POST
INPUT1 : input one text
INPUT2 : input two text
// all other members of $_POST array
Array
--------------
// assuming that page was called via HTTP GET
INPUT10 : input ten text
INPUT11 : input eleven text
// all other members of $_GET array
...
我知道我可以在孩子的内部循环中创建一个迭代器,然后调用$father[0]、$father[1],并以某种方式将数组的名称转换为字符串,但我希望有人能指导我使用一种更“优雅”的方式来做事情。你的数组没有关于孩子的任何信息。设置适当的键:
$father = array ( 'getallheaders' => getallheaders(), '$_POST' => $_POST, '$_GET' => $_GET );
然后用以下方法更改您的foreach
:
foreach( $father as $childname => $child )
{
$info .= "$childname\n";
(...)
}
您的阵列没有任何关于子级的信息。设置适当的键:
$father = array ( 'getallheaders' => getallheaders(), '$_POST' => $_POST, '$_GET' => $_GET );
然后用以下方法更改您的foreach
:
foreach( $father as $childname => $child )
{
$info .= "$childname\n";
(...)
}
你赢了我!你赢了我!