如何将数组值从 php 传递给 url



>我的 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>

米菲普

$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"]/

可以这样做吗?如果是这样,请帮忙。

使用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

最新更新