We have the following code:
$fruits = array(
(object) array(
'name' => 'orange',
'country' => 'brazil',
'qty' => 23,
'destination' => 'romania'
),
(object) array(
'name' => 'pinapple',
'country' => 'thailand',
'qty' => 3,
'destination' => 'germany'
),
(object) array(
'name' => 'carrot',
'country' => 'romania',
'qty' => 250,
'destination' => 'france'
),
(object) array(
'name' => 'bannana',
'country' => 'kenya',
'qty' => 50,
'destination' => 'sweden'
),
(object) array(
'name' => 'melon',
'country' => 'romania',
'qty' => 50,
'destination' => 'uae'
)
);
function testing($fruits)
{
for($i = 0, $size = sizeof($fruits); $i < $size; $i++)
{
$fruit = $fruits[$i];
$fruits[$i]->qty = $fruit->qty * 100;
unset($fruit->destination);
unset($fruit->test);
unset($fruit->country);
}
return $fruits;
}
var_dump($fruits);
testing($fruits);
var_dump($fruits);
?>
If you run that code, the $fruits array has its items changed since it's passed as reference.
The question is: how can we pass it so that the testing() function does not alter the $fruits?
Thanks to all.