I have two variables, which are both arrays:
$var1=array();
$var1['something']['secondary_something'][1]="foo";
$var1['something']['secondary_something'][2]="foo";
$var1['something']['secondary_something'][3]="foo";
$var1['something']['secondary_something'][4]="foo";
Now I have a function, that takes an array for input:
function something($input=array()){
print_r($input);//print the array out
}//end of function
But I need $input to be like a reference to $var1, so when I call the function, appending to variable 2 ($input) like this:
$myInputVar=array();
$myInputVar['something']['secondary_something'][]="foo";
$myInputVar['something']['secondary_something'][]="foo";
//Notice how I append to the var above, not giving a key name in the third dimension of the array.
something($myInputVar);
Now that would simply print:
Array ( [something] => Array ( [secondary_something] => Array ( [0] => foo [1] => foo ) ) )
But I need the second var ($input, from the function) to be a reference of the first var ($var1).
So, the end result should be:
Array ( [something] => Array ( [secondary_something] => Array ( [5] => foo [6] => foo ) ) )
Some guys have told me to use the =& (which makes one var a reference to another), but I just can’t seem to get my head around how I would do it with =& in this case.
Is what I’m trying to do even possible? If so, could you please shine some light on it.
I am struggling to understand what you are trying to achieve.
Why would you print the array out?
You always need a value and an array if you want to push something into the array.
You can do this with
Then calling with
I hope this helps
EDIT