Gal Gal - 1 year ago 82
PHP Question

How to push both value and key into array

Take a look at this code:

$GET = array();
$key = 'one=1';
$rule = explode('=', $key);
/* array_push($GET, $rule[0] => $rule[1]); */

I'm looking for something like this so that:

/* output: $GET[one => 1, two => 2, ...] */

Is there a function to do this? (because
won't work this way)

Answer Source

Nope, there is no array_push() equivalent for associative arrays because there is no way determine the next key.

You'll have to use

$arrayname[indexname] = $value;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download