1

i have some thing like this in my html multi checkbox

<label for="Status"><h2>Status:</h2></label>
<input type="checkbox" name="status[]" value="new">New<br>
<input type="checkbox" name="status[]" value="assigned">Assigned<br>
<input type="checkbox" name="status[]" value="resolved">Resolved<br>
<input type="checkbox" name="status[]" value="verified">Verified<br>
<input type="checkbox" name="status[]" value="closed">Closed<br>

myphp

$status = $_POST["status"];

$url = "http://some-example.com/project="abc" and state in [".$status."]/";
header("Location:$url");

i want the url to be like:

$url = "http://some-example.com/project="abc" and state in ["new","assigned","resolved","verified","closed"]/

is it possible to do this? if so please help.

Jonnix
  • 4,121
  • 1
  • 30
  • 31
Lakshmikanth B
  • 95
  • 1
  • 1
  • 9
  • Possible duplicate of [How to pass an array within a query string?](https://stackoverflow.com/questions/6243051/how-to-pass-an-array-within-a-query-string) – Zico Aug 03 '17 at 08:58

1 Answers1

2

Use http_build_query :

$url = "http://some-example.com/" . http_build_query([
    "project" => "abc",
    "state" => ["new","assigned","resolved","verified","closed"]
]);

Output :

http://some-example.com/project=abc&state%5B0%5D=new&state%5B1%5D=assigned&state%5B2%5D=resolved&state%5B3%5D=verified&state%5B4%5D=closed
Ralph John Galindo
  • 1,190
  • 6
  • 11