Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php foreach未通过第二次获取阵列数据_Php_Javascript_Arrays - Fatal编程技术网

Php foreach未通过第二次获取阵列数据

Php foreach未通过第二次获取阵列数据,php,javascript,arrays,Php,Javascript,Arrays,这个问题建立在。。。我有一个php表单,提交很好。我添加了一个“添加更多”功能,它再次添加了整个字段集 //access changes if ($reqtype=="accesschange"){ $subject="FORM: Request Access Change(s) To Exisiting Folder"; $note .="Full Path of folder to change access: $fullpath \n\n"; if($userper

这个问题建立在。。。我有一个php表单,提交很好。我添加了一个“添加更多”功能,它再次添加了整个字段集

//access changes
if ($reqtype=="accesschange"){
    $subject="FORM: Request Access Change(s) To Exisiting Folder";
    $note .="Full Path of folder to change access: $fullpath \n\n";
    if($userpermissiongroup != ""){
        $note .="User Permission Group to be changed: $userpermissiongroup \n";
    }
    if($addreadaccess != ""){
        $note .="Additional users requiring read access: $addreadaccess \n";
    }
    if($addauthoraccess != ""){
        $note .="Additional users requiring author access: $addauthoraccess \n";
    }
    if($removeaccess != ""){
        $note .="Users to be removed from access: $removeaccess \n";
    }
    $note .="Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes: $supervisor \n\n";
    $note .="Phone number of approving official: $phoneapprover \n";

}
如果用户单击更多,则此foreach将通过添加的字段运行:

    $addQues = array(
        "Full Path of folder to change access:",
        "User Permission Group to be changed:",
        "Additional users requiring read access:",
        "Additional users requiring author access:",
        "Users to be removed from access:",
        "Data Steward, Program Manager, Project Lead, or Supervisor who can authorize access changes:",
        "Phone number of approving official:",          
    );

foreach($_REQUEST['addfield'] as $k => $value) {
        $note .= "$addQues[$k] $value";
    }
它将采用第一个字段,即php添加的字段。。。然后是通过javascript添加的第一个字段集(用户添加),但不需要第二个或第三个字段集。。。因此,我的数据最终看起来像:

要更改访问权限的文件夹的完整路径:t:\this drive User Permission 要更改的组:dv组需要读取访问权限的其他用户: jfla需要作者访问权限的其他用户:azann用户 已从访问中删除:dlint数据管理员、项目经理、项目经理 可以授权访问更改的领导或主管:gpone电话 批准官员编号:888-888-7777

要更改访问权限的文件夹的完整路径:o:\driveUser权限组 要更改:odrive group需要读取访问权限的其他用户: sjonesAdditional需要作者访问权限的用户:pvalleUsers 已从访问中删除:kpowerData管理员、项目经理、项目经理 可授权访问更改的领导或主管:bzellPhone 批准官员编号:777-777-7777

i:\new i group urusa mmalone jjon yokis 888-999-555

u:\u组phammer midnite bmarley gdead 777-444-2222

为什么foreach没有第二次拿起addQues()

变量转储$请求

数组(22){“名称”=>string(1)”“[“电子邮件”=>string(14)”“[“添加”=>string(0)”“[“citystate”]=>string(4)”,“[“电话1”=>string(0)”“[“电话2”]=>string(0)”[“请求类型”=>string(12)“访问更改”[“新路径”=>string(0)”“[“用户访问”=>string(0)”,“ryesaccess”=>string(0)”,“ryesaccess”=>string(0)”[“审批官”=>string(0)”=>string(0)“[“comments”]=>string(0)“[“fullpath”]=>string(14)”t:\this drive“[“userpermissiongroup”]=>string(8)”dv”[“addreadaccess”]=>string(9)“jflat”[“addauthoraccess”]=>string(5)“dlit”[“supervisor”]=>string(6)“lnat”[“phoneapprover”]=>string(12)“888-888-7777”[“addfield”=>array(21){>0]=>string(9)“o:\drive”=>string(12)“odrive group”[2]=>string(6)“sjones”[3]=>string(6)“pvae”[4]=>string(7)“kpow”[5]=>string(8)“bdez”[6]=>string(12)“777-777-7777”[7]=>string(7)“i:\new”[8]=>string(7)“i group”[9]=>string(5)“urusa”[10]=>string(7)“mmalone”[11]=>string(4)“jjon”=>“888-999-555”[14]=>string(4)“u:\”[15]=>string(7)“u组”[16]=>string(7)“phammer”[17]=>string(7)“midnite”[18]=>string(7)“bmarley”[19]=>string(5)“gdead”[20]=>string(12)“777-444-2222”}[“c(id”]=>string(0)}

我得到的信息的var\u转储将是:var\u dumb($\u REQUEST['addfield']

数组(21){[0]=>string(9)“o:\drive”=>string(12)”驱动器 组“[2]=>string(6)“sjones”[3]=>string(6)“pval”[4]=> 字符串(7)“kpow”[5]=>字符串(8)“bdezl”[6]=>字符串(12) “777-777-7777”[7]=>字符串(7)“i:\new”[8]=>字符串(7)“i组” [9] =>string(5)“urusa”[10]=>string(7)“mmalone”[11]=>string(4) “jjon”[12]=>string(5)“yokis”[13]=>string(11)“888-999-555”[14]=> 字符串(4)“u:\”[15]=>字符串(7)“u组”[16]=>字符串(7)“Phamer” [17] =>string(7)“midnite”[18]=>string(7)“bmarley”[19]=>string(5) “gdead”[20]=>字符串(12)“777-444-2222”}


正如您在
var_dump
输出中所看到的,
addfield
是一个数组类型的字段,其中包含21个元素。具体来说,它包含您前面提到的三组字段值,但没有以任何方式组织。这就是为什么您只获得第一组的文本(对于
$k
,值为0…6)当您在
$\u请求['addfield']
中循环时


如果我是你,我可能会用与静态字段相同的方式命名动态添加的字段,即
userpermissiongroup[]
addreadaccess[]
等,然后将所有字段作为数组处理。

正如您在
var\u dump
输出中所看到的,
addfield
是一个数组类型的字段,其中包含21个元素。具体来说,它包含您前面提到的三组字段值,但没有以任何方式组织。这就是为什么您只获取第一组的文本(值0…6表示
$k
)当您在
$\u请求['addfield']
中循环时


如果我是你,我可能会用与静态字段相同的方式命名动态添加的字段,即
userpermissiongroup[]
addreadaccess[]
等,然后将所有字段作为数组处理。

如果我理解正确,您希望有一个表单,可以在其中填写有关文件权限请求的详细信息,并将更多请求动态添加到同一表单中

您可能没有正确设置表单字段的名称。如果第一个和第二个字段集有效,但其他字段集无效,则表单中最初的字段集与动态添加的字段集具有不同的命名约定,并且动态添加的字段集相互冲突

我建议您使用Chrome对其进行测试,并打开开发人员工具,在Javascript更新页面时查看页面的实时HTML代码

上一个问题的表单字段名称如下:

<fieldset>
    <input name="fullpath" (...) />
    <input name="userpermissiongroup" (...) />
    <input name="addreadaccess" (...) />
    (...)
</fieldset>

(...)
如果您想要几个这样的字段集,您需要使用数组表示法,正如在上一个问题的答案中所指出的那样

这可能有点棘手,除非你知道你在做什么

<fieldset>
    <input name="fullpath[]" (...) />
    <input name="userpermissiongroup[]" (...) />
    <input name="addreadaccess[]" (...) />
    (...)
</fieldset>
<fieldset>
    <input name="fullpath[]" (...) />
    <input name="userpermissiongroup[]" (...) />
    <input name="addreadaccess[]" (...) />
    (...)
</fieldset>

(...)
(...)
…您的数据将被提交,但它们不会很好地分组。最好将它们分组为对象

<fieldset>
    <input name="request[0][fullpath]" (...) />
    <input name="request[0][userpermissiongroup]" (...) />
    <input name="request[0][addreadaccess]" (...) />
    (...)
</fieldset>
<fieldset>
    <input name="request[1][fullpath]" (...) />
    <input name="request[1][userpermissiongroup]" (...) />
    <input name="request[1][addreadaccess]" (...) />
    (...)
</fieldset>

(...)
(...)
这样,每个添加的请求数据都可以很好地分组