使用PHP [duplicate]将具有相同name属性的每个字段的值放入数组中

This question already has an answer here:

I have two fields (at minimum) that both have the same name attribute. Using a little jQuery, the user can add more text boxes using jQuery's .clone() feature. Every possible input they add will have the same name attribute as the first two. I want to try to use php to create a comma separated list of every input value after the form is submitted.

$competitor_names = $_POST['competitor-name'];
$competitorList = '';
foreach($competitor_names as $competitorList) {
    $competitorList = $competitorList.', ';
}
</div>

The function implode() seems to be what you're looking for :

$competitor_names = $_POST['competitor-name'];
$competitorList = implode(',', $competitor_names);