Passing arrays as url parameter

前端 未结 10 1850
礼貌的吻别
礼貌的吻别 2020-11-22 12:32

What is the best way that I can pass an array as a url parameter? I was thinking if this is possible:

$aValues = array();

$url = \'http://www.example.com?a         


        
10条回答
  •  不要未来只要你来
    2020-11-22 12:40

    This isn't a direct answer as this has already been answered, but everyone was talking about sending the data, but nobody really said what you do when it gets there, and it took me a good half an hour to work it out. So I thought I would help out here.

    I will repeat this bit

    $data = array(
    'cat' => 'moggy',
    'dog' => 'mutt'
    );
    $query = http_build_query(array('mydata' => $data));
    $query=urlencode($query);
    

    Obviously you would format it better than this www.someurl.com?x=$query

    And to get the data back

    parse_str($_GET['x']);
    echo $mydata['dog'];
    echo $mydata['cat'];
    

提交回复
热议问题