In my class, I have a public variable:
public $full_rows = array("text");
I want to be able to add to that array, like so:
$form->addarray("full_rows", array("url","name"));
So I have this function:
public function addarray($arrayname, $array = array()) {
array_merge($this->$arrayname, $array);
}
Except it's not affecting the array full_rows
at all. Why not?
Edit
Thanks to roullie for the correct answer. Turns out I'd forgotten that array_merge
returns the merged array rather than just doing it. I thought it was a problem with variable variables (as I'd never used them before).
Here is my final function:
public function addarray($arrayname, $array = array()) {
if((isset($this->$arrayname)) && (is_array($array))) {
$this->{$arrayname} = array_merge($this->{$arrayname}, $array);
} else {
return false;
}
}