spacer.png, 0 kB
spacer.png, 0 kB
Home arrow PHP arrow PHP: Exchange Value of Variables
PHP: Exchange Value of Variables PDF Print E-mail
Written by Administrator   
giovedě, 31 dicembre 2009

When exchanging the values of two variables, a third 'temp' variable is generally constructed to temporarily store one of the variables while the exchange is performed.
Here below a simple example:

if ($exchange) {
  $temp = $v1;
  $v1 = $v2;
  $v2 = $temp
}

There is however a more elegant way in PHP using the language construct list:

if ($exchange) {
  list($v1,$v2) = array($v2,$v1);
}

Last Updated ( giovedě, 31 dicembre 2009 )
 
< Prev   Next >
spacer.png, 0 kB
spacer.png, 0 kB
spacer.png, 0 kB