Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 560 Bytes

Q41-45.md

File metadata and controls

32 lines (26 loc) · 560 Bytes

Q41-45

标签(空格分隔): Driphp


##NO.41如何将数组当做url中的GET参数传递? ###问题描述 如何将下列数据作为URL参数传递?

$data = array(
    1,
    4,
    'a' => 'b',
    'c' => 'd'
);

###使用http_build_query()

$query = http_build_query(array('aParam' => $data));

$query内容如下:

aParam%5B0%5D=1&aParam%5B1%5D=4&aParam%5Ba%5D=b&aParam%5Bc%5D=d

我们使用$_GET接收的时候,即可接收到数组

Array ( [aParam] => Array ( [0] => 1 [1] => 4 [a] => b [c] => d ) )