I'm not really sure how to ask this question which is why I think I can't find a suitable answer...
I have a simple function and inside that function I'm assigning an existing array to a variable. By changing the variable, I would like to update the array as well. I'm well aware that I can do it by pushing the variable data back out to the array but I'm curious if I can use this in a more simple fashion... almost as if I'm storing the variable as a value instead of a reference to the array.
Here's the function with my notes
function __construct($name, $action, $a){ # $a accepts a series of multidimensional sub-arrays
$f = $this -> form; #passing the reference in here
$f['name'] = $name; #ref
$f['action'] = $action; #ref
foreach($a as $k => $v){
if(is_array($f[$k])){
array_push($f[$k], $v);
}else{
$f[$k] = $v;
}
}
# $f now contains a new value however I want to know if it's possible to make $f directly change $this -> form without a back reference
$this -> form = $f; #this solves the problem but is there a better way?
var_dump($this -> form);
}
It shouldn't make much of a difference but here's $this -> form
protected $form = array(
"title" => "",
"name" => "",
"id" => "",
"class" => "Frm-cb", #default class for all forms
"action" => "",
"method" => "POST",
"rel" => "",
"topmsg" => "",
"autocomplete" => "",
"inputs" => array(),
"buttons" => array(),
"props" => array(),
"attributes" => array()
);
Just curious if it's possible - thanks!