PHP: How to dynamically add to http_build_query?

Posted by oni-kun on Stack Overflow See other posts from Stack Overflow or by oni-kun
Published on 2010-04-09T11:04:24Z Indexed on 2010/04/09 11:13 UTC
Read the original article Hit count: 517

Filed under:
|
|

I have a scraping object basically. I want to be able to add POST variables to it like

$obj->addvar('Name', 'Value');

What I have now is this:

  function addvar($var, $val) {
    $postvars[] = Array($var=>$val); 
  }
  function initiate() {
    $this->q = $postvars;
  }
  if(!empty($this->post)) {
    $this->params = http_build_query($q);
  }

I haven't tested because it's too incomplete, But would my addvar() function work? How on earth do I append a key+value to the array so http_build_query would accept it?

IE (this is what I want):

$obj->addvar('username', 'abc');
$obj->addvar('password', 'foobar');
$obj->send(); //..

© Stack Overflow or respective owner

Related posts about php

Related posts about array