Passing arrays as url parameter

前端 未结 10 1852
礼貌的吻别
礼貌的吻别 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 13:00

    please escape your variables when outputting (urlencode).

    and you can’t just print an array, you have to build your url using a loop in some way

    $url = 'http://example.com/index.php?'
    $first = true;
    foreach($aValues as $key => $value) {
      if(!$first) $url .= '&';
      else $first = false;
      $url .= 'aValues['.urlencode($key).']='.urlencode($value);
    }
    

提交回复
热议问题