如何从PHP中的数组中删除(隐藏)索引.使用http_build_query [英] How to remove(hide) index from array in PHP. Using http_build_query

查看:126
本文介绍了如何从PHP中的数组中删除(隐藏)索引.使用http_build_query的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to pass an array as a url parameter ? I'm using http_build_query(), array_shift() and urldecode().

我有这个数组:

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

当我使用http_build_query时,urldecode将返回:

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

当我使用array_shift时将返回:

0=ios&1=android&2=windows

我要这样做:

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

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

Please help me. How to remove(hide) index from array.

谢谢.

推荐答案

$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.

这篇关于如何从PHP中的数组中删除(隐藏)索引.使用http_build_query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆