未定义的索引PHP数组

时间:2017-03-02 21:30:32

标签: php arrays foreach

我是PHP的新手。我是一个有6个字段的HTML表单。 6个字段可以填写10次,以占更多人。我试图将输入放入数组中,然后打印数组,以便显示每个子项的数据。我得到了一个未定义的偏移错误,而且我被卡住了。

我的php如下:

if (isset($_POST['submit'])) {
    $name = $_POST['Name'];
    $gender = $_POST['Gender'];
    $month = $_POST['Month'];
    $day = $_POST['Day'];
    $year = $_POST['Year'];
    $rel = $_POST['Relationship'];
}

foreach( $name as $key => $names ) {
    $child = "<b>Name</b> - " .$names. ", Gender - " .$gender[$key]. ", Month -      "     .$month[$key]. ", Day - " .$day[$key]. ", Year - " .$year[$key]. ",     Relationship - " .$rel[$key] ."<br>";
}

0 个答案:

没有答案