2017-08-03 58 views
1

传递给一个网址,我有一些像这样的事情在我的HTML多选框如何数组值从PHP

<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

的可能的复制(https://stackoverflow.com/questions/6243051/如何对传递一个阵列中之查询字符串) – Zico

回答

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