In the project, it is necessary to perform calculations with intermediate saving of each stage into variables. After that, collect all the results into an array with keys of the same name as a variable. Then transfer the array to another function and iterate over it, changing the values only inside the function, without changing the original ones.
// Решил, что в начале работы обнулю все переменные и соберу ссылки на них в массив $var1 = $var2 = $var3 = 0; $busket['var1'] = &$var1; $busket['var2'] = &$var2; $busket['var3'] = &$var3; // далее идут вычисления $var1 = ...; $var2 = ...; $var3 = ...; // передаём массив в другую функцию $niceOutput = string_formatting($busket); // и вот тут переменные $var1 .. $var3 уже изменённые, // чего быть не должно But inside the function I already need to work with a copy of the array, in which the values are not linked by references to the original variables.
function string_formatting($busket) { // вот так скопировать не получается, значения всё равно передаются ссылками $copyBusket = $busket; unset($busket); foreach ($copyBusket as $name => &$value) { // меняем $value } } I am only interested in educational purposes in order to understand how to unlink variable references, since The problem has already been solved differently.
$copyBusketfrom$copyBusketin a loop, not through assignment? Or viaarray_flip(array_flip($busket));- BOPOH