getVars Function for PHP.


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

Transform $_GET or $_POST in a string to add to an URL and send variables and values.
Argument: Receive an $_GET O $_POST array function.
Returns: variables concatenation to add to the URL.


Copy this code and paste it in your HTML
  1. function getVars($arrVars){
  2. $txtGetVars='';
  3. foreach ($arrVars as $Key=>$Value){
  4. if (gettype($Value)=='array'){
  5. for($k=0; $k <= count($arrVars[$Key])-1;$k++){
  6. $txtGetVars .= ($txtGetVars=='')? $Key.'[]='$arrVars[$Key][$k] :'&'.$Key.'[]='.$arrVars[$Key][$k];
  7. }
  8. else{
  9. $txtGetVars .=($txtGetVars=='')? $Key.'='.$Value :'&'.$Key.'='.$Value ;
  10. }
  11. }
  12. }
  13. return $txtGetVars;
  14.  
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.