Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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 如何像这样进行HTML数组输入?_Php_Html_Input - Fatal编程技术网

Php 如何像这样进行HTML数组输入?

Php 如何像这样进行HTML数组输入?,php,html,input,Php,Html,Input,我有一个循环的laravel代码,这是示例输入 <input type="hidden" value="{{ $question['question'] }}" name="custom_form[question][{{ $question['name'] }}]" /> <input type="text" name="custom_form[answer][{{ $question['name'] }}]" /> 如果在上没有类似的内容,那么如何在foreach循

我有一个循环的laravel代码,这是示例输入

<input type="hidden" value="{{ $question['question'] }}" name="custom_form[question][{{ $question['name'] }}]" />
<input type="text" name="custom_form[answer][{{ $question['name'] }}]" />
如果在
上没有类似的内容,那么如何在foreach循环上执行此操作以获得类似的结果

你目前的移民身份是什么?归化公民
你有绿卡吗?对


我只想对您拥有的一个数组进行
foreach
,因为键与问题和答案都匹配。然后可以引用另一个数组的键来获取当前值

foreach($_POST['custom_form']['question'] as $key => $question) {
     echo htmlentities($question . ' ' . $_POST['custom_form']['answer'][$key]) . '<br>';
}
foreach($\u POST['custom\u form']['question']作为$key=>$question){
回显Htmlenties($question.'.$\u POST['custom_form']['answer'][$key])。
; }
如果可以假设所有字段都始终存在,则应该可以:

$transposed = [];
foreach($arr['question'] as $key => $value) {
    $transposed[$key] = array('question' => $value, 'answer' => $arr['answer'][$key]);
}
但是,如果不能,则需要进行有效性检查:

$transposed = [];
foreach($arr['question'] as $key => $value) {
    if (array_key_exists($key, $arr['answer'])) {
        $transposed[$key] = array(
            'question' => $value,
            'answer'   => $arr['answer'][$key]
        );
    }
}
$transposed = [];
foreach($arr['question'] as $key => $value) {
    if (array_key_exists($key, $arr['answer'])) {
        $transposed[$key] = array(
            'question' => $value,
            'answer'   => $arr['answer'][$key]
        );
    }
}