在php中通过url传递数组

时间:2012-03-10 02:02:38

标签: php

我希望通过url传递一个数组。我查看了passing arrays as url parameter。还有其他方法吗?以下是我的代码

$result=Users.LoggedInUsers();
header('Location: http://localhost/Campus/Users.php?id='.$result.'');

2 个答案:

答案 0 :(得分:1)

查看http_build_query

example

<?php
$arr = array(1,2,3,4);
echo http_build_query(array('arr'=>$arr));
//arr%5B0%5D=1&arr%5B1%5D=2&arr%5B2%5D=3&arr%5B3%5D=4

答案 1 :(得分:0)

您可以轻松serialize,然后将其反序列化以将其恢复为数组:

$result=serialize(Users.LoggedInUsers());
header('Location: http://localhost/Campus/Users.php?id='.$result.'');