There are several checkboxes belonging to the name Category and giving different values. How can I write the values ​​of all selected checkboxes in a string, separated by commas?

<span> <div><input type="checkbox" name="category" value="men">men</div> <div><input type="checkbox" name="category" value="female">female</div> <div><input type="checkbox" name="category" value="a1">a1</div> <div><input type="checkbox" name="category" value="a2">a2</div> </span> 

    1 answer 1

     <span> <div><input type="checkbox" name="category[]" value="men">men</div> <div><input type="checkbox" name="category[]" value="female">female</div> <div><input type="checkbox" name="category[]" value="a1">a1</div> <div><input type="checkbox" name="category[]" value="a2">a2</div> </span> 

    php

     implode(',', $_POST['category']); 
    • The problem is that it does not create an array, but sets the value of the last selected element - dmitriy kiryushin
    • @dmitriy kiryushin take a closer look at my post. - lampa
    • Thanks for the much-needed answer) - dmitriy kiryushin