I would like to send an array in the input form element.
My array:
Array( [0] => 55 [1] => 1 [2] => 4 )
HTML <input>
tag:
<input type="hidden" name="category" value="'.$category.'" />
This is the URL my code resulted in:
http://localhost/search?&category%5B%5D=55&category%5B%5D=1&category%5B%5D=4
But I also get this PHP Notice:
PHP Notice: Array to string conversion
How do I send an array via HTML form correctly?
============================
I found this solution:
foreach ($category as $item) {
echo '<input type="hidden" name="categories[]" value="'.$item.'" />';
}
Prepare your array $category
. Example:
echo '<div align="center">
<form method="GET" action="/search" />
<input type="hidden" name="search" value="'.$search.'" />';
foreach ($category as $item){
echo '<input type="hidden" name="categories[]" value="'.$item.'" />';
}
echo '<input type="submit">
</form>
</div>';
And get:
if(isset($_GET['categories'])) {
$categories = $_GET['categories'];
}