为多个变量分配相同的值

时间:2021-07-20 12:50:38

How can I assign the same value for multiple variables in PHP?

如何为PHP中的多个变量分配相同的值?

I have something like:

我有类似:

$var_a = 'A';
$var_b = 'A';
$same_var = 'A';
$var_d = 'A';
$some_var ='A';

In my case, I can't rename all variables to have the same name (that would make things more easy), so is there any way to assign the same value to all variables in a much more compact way?

在我的例子中,我不能将所有的变量重命名为具有相同的名称(这会使事情变得更简单),那么是否有方法以更紧凑的方式为所有变量分配相同的值?

1 个解决方案

#1


196  

$var_a = $var_b = $same_var = $var_d = $some_var = 'A';

#1


196  

$var_a = $var_b = $same_var = $var_d = $some_var = 'A';