php无法发送已发布的数组元素

php无法发送已发布的数组元素,php,Php,我使用AJAX post方法成功地将以下值传递到我的PHP文件 name:John email:test@test.com comments:Hello category_list[]:Books category_list[]:Documents 问题是以下代码发送的是HelloArray,而不是HelloBooksDocuments。你能帮我找出我的错误吗 $email = $_POST["email"]; $name = $_POST["name"]); $comments =

我使用AJAX post方法成功地将以下值传递到我的PHP文件

name:John
email:test@test.com
comments:Hello
category_list[]:Books
category_list[]:Documents
问题是以下代码发送的是
HelloArray
,而不是
HelloBooksDocuments
。你能帮我找出我的错误吗

$email = $_POST["email"];
$name = $_POST["name"]);    
$comments = $_POST["comments"];
$categories = $_POST["category_list"];  //the problem is here  
替换此行:

$comments= $comments.$categories;
与:

原因是变量$categories是一个数组,需要将其转换为字符串

这个你可以用。如果希望它们之间用逗号分隔,则将其作为第一个参数传递,替换我上面建议的空字符串“”


当然,您可以更改此分隔符,并使用您选择的另一个分隔符。

使用其预期输出,可能会将分隔符更改为
“”
$comments= $comments.implode("", $categories);