问题
How to pass an array as a url parameter ? I'm using http_build_query()
, array_shift()
and urldecode()
.
I have this array:
$array = array(
'phone' => array('ios', 'android', 'windows')
);
When i use http_build_query
and urldecode
will return:
phone[0]=ios&phone[1]=android&phone[2]=windows
When i use array_shift
will return:
0=ios&1=android&2=windows
I want to this:
test.php?phone=ios&phone=android&phone=windows
Please help me. How to remove(hide) index from array.
Thanks in advance.
回答1:
$queryString = "?phone=" . create_query_string(array('ios','windows','android'));
$array = create_array_from_query_string(substr($queryString, 7));
function create_query_string($array) {
return implode('&phone=', $array);
}
function create_array_from_query_string($queryString) {
return explode('&phone=', $queryString);
}
I suggest using above approach. But you must be familiar with your query string.
来源:https://stackoverflow.com/questions/32344203/how-to-removehide-index-from-array-in-php-using-http-build-query