Andy Andy -4 years ago 112
PHP Question

Getting weird error whilst populating an array

What I'm trying to do is transfer the contents of the array difference() to the array tempStore. The error I am getting is 'Fatal error: Can't use function return value in write context in' on line 4 ($tempStore($x) = $difference($x);). What am i doing wrong here and how do i fix it?

$difference = array("","","","","","","");

for ($x = 1; $x <= 6; $x++){
$tempStore($x) = $difference($x);
}

for ($x = 1; $x <= 6; $x++){
echo $tempStore($x);
}

Answer Source

You just need to use [] instead of ()

for ($x = 1; $x <= 6; $x++){
    $tempStore[$x] = $difference[$x];
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download