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

时光总嘲笑我的痴心妄想 提交于 2019-12-24 11:28:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!