PHP 如何读取名称中带有空方括号的表单变量

PHP How do I read the form variables with empty square brackets in their name

在我提交的 php 文件中,我可以很容易地读取以下变量(见附图)

$mobile = $_REQUEST['mobile'];  
$about = $_REQUEST['about'];  
$comment = $_REQUEST['comment']; 

现在我的问题是..如何读取“category[]”表单值?

就像阅读普通变量一样阅读它。

$category = $_REQUEST['category']; 

与其他变量不同,它将 return 你 PHP 数组。您可以像正常 PHP Array.

一样遍历此变量
foreach($category as $cat) {
    echo $cat;
}

Make sure your check if request actually have the value you're looking for by using isset(). Otherwise above code might throw undefined indexed error.

你应该试试

foreach ($_REQUEST['category'] as $category) {
    var_dump($category);
}

获取数组变量

$categories = $_REQUEST['category'];
var_dump($categories);

试试这个,如果需要,它还会显示索引或键

print_r ($_REQUEST['category']);