note 39444 added to language.operators.assignment
| From: | jeronimo at DELETE_THIS dot transartmedia dot com | Date: | Thu, 29 Jan 2004 00:27:46 +0000 |
| Subject: | note 39444 added to language.operators.assignment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64340@lists.php.net to get a copy of this message | ||
If you want to swap values between variables without using an intermediary, try using the list() and
array() language constructs. For instance:
<?
// Initial values.
$biggest = 1;
$smallest = 10;
// Instead of using a temporary variable...
$temp = $biggest;
$biggest = $smallest;
$smallest = $temp;
// ...Just swap the values.
list($biggest, $smallest) = array($smallest, $biggest);
?>
This works with any number of variables; you're not limited to just swapping two.
Cheers,
Jeronimo
----
Manual Page -- http://www.php.net/manual/en/language.operators.assignment.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39444
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39444&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39444&report=yes
Search -- http://master.php.net/manage/user-notes.php