如何从 PHP 中的数组中删除(隐藏)索引。使用 http_build_query

How to remove(hide) index from array in PHP. Using http_build_query

如何将数组作为 url 参数传递?我正在使用 http_build_query()array_shift()urldecode()

我有这个数组:

$array = array(
    'phone' => array('ios', 'android', 'windows')
);

当我使用 http_build_queryurldecode 时 return:

phone[0]=ios&phone[1]=android&phone[2]=windows

当我使用 array_shift 时将 return:

0=ios&1=android&2=windows

我想要这个:

test.php?phone=ios&phone=android&phone=windows

请帮助我。如何从数组中删除(隐藏)索引。

提前致谢。

$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);
}

我建议使用上述方法。但是您必须熟悉您的查询字符串。