Posted By

MonsterDev on 07/14/12


Tagged

url String query uri parameters multiple param


Versions (?)

Uri multiple parameters


 / Published in: PHP
 

This function allow you ti have multiple parameters in your query string. Ex : id=12&name=Doe&id=42&nickname=Monster

  1. public static function getMultipleParameters()
  2. {
  3. $query = $_SERVER['QUERY_STRING'];
  4. $vars = array();
  5. $second = array();
  6. foreach (explode('&', $query) as $pair) {
  7. list($key, $value) = explode('=', $pair);
  8. if('' == trim($value)){
  9. continue;
  10. }
  11. /// Si il existe une clé (donc le parametre est multiple)
  12. if (array_key_exists($key, $vars)) {
  13. /// permet de réécrire le premier parametre a l'interieur du tableau
  14. if (!array_key_exists($key, $second))
  15. $second[$key][] .= $vars[$key];
  16. $second[$key][] = urldecode($value);
  17. } else {
  18. $vars[$key] = urldecode($value);
  19. }
  20. }
  21. return array_merge($vars, $second);
  22. }

Report this snippet  

You need to login to post a comment.