tags:

views:

988

answers:

1

I'm trying to pass key values pairs within PHP:

// "initialize"
private $variables;
// append
$this->variables[] = array ( $key = $value)
// parse
foreach ( $variables as $key => $value ) {
   //..
}

But it seems that new arrays are added instead of appending the key/value, nor does the iteration work as expect. Please let me know what the proper way is.

Many many thanks & sorry for asking "such" questions ;)

Solution

$this->variables[$key] = $value;

did the trick - the iteration worked as described above.

+4  A: 

I think you may be looking for:

$this->variables[$key] = $value;

The way you have it right now you are creating an array of arrays, so you would have to do this:

foreach($this->variables as $tuple) {
    list($key, $value) = $tuple;
}
Paolo Bergantino
Thank you very much Paolo, you saved my evening ;)
MrG