Uri multiple parameters


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.