我在html multi复选框中有这样的东西
<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");
我希望网址如下:
$url = "http://some-example.com/project="abc" and state in ["new","assigned","resolved","verified","closed"]/
可以这样做吗?如果有的话请帮忙。
答案 0 :(得分:2)
使用http_build_query
:
$url = "http://some-example.com/" . http_build_query([
"project" => "abc",
"state" => ["new","assigned","resolved","verified","closed"]
]);
输出:
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