Last Updated: February 25, 2016
·
4.569K
· arazmus

Assign Multi Vars to the same value in PHP

Sometimes, but not all that often, we have to assign multiple variables to the same initial value.

we can do this easily in PHP with the following code:

<?php
$var1 = $var2 = $var3 = $var4 = 'some_value';
?>

It may look a little odd but its very simple - all we are doing is assigning the first variable to the value of the second variable, and so on and so forth, then assigning the last variable to the actual value you want all your vars to be.

I have used this many a time were i have to set multiple vars to null before processing.