Say for instance I have ...
$var1 = "ABC"
$var2 = 123
and under certain conditions I want to swap the two around like so...
$var1 = 123
$var2 = "ABC"
Is there a PHP function for doing this rather than having to create a 3rd variable to hold one of the values then redefining each, like so...
$var3 = $var1
$var1 = $var2
$var2 = $var3
For such a simple task its probably quicker using a 3rd variable anyway and I could always create my own function if I really wanted to. Just wondered if something like that exists?
Update: Using a 3rd variable or wrapping it in a function is the best solution. It's clean and simple. I asked the question more out of curiosity and the answer chosen was kind of 'the next best alternative'. Just use a 3rd variable.
b = a xor b
,a = a xor b
,b = a xor b
should do the trick... Dunno if theres a function, I'm not good with PHP. – Begat