How to Assign the Same Value to Multiple Variables?

This is a simple tip but most experienced PHP programmers don’t know that it even exists.
If you want to have a bunch of variables contain the same value, your common sense will tell you to do this:

$var1 = "text";
$var2 = "text";
$var3 = "text";

What if I told you there was an easier way? In fact, a way which works in most programming languages. There it is:

$var1 = $var2 = $var3 = "text";

Now you know how to save some time.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.