Skip to content

Instantly share code, notes, and snippets.

@yookoala
Created August 13, 2020 07:53
Show Gist options
  • Save yookoala/d97f3b3e67cd6769563255b214ffd54f to your computer and use it in GitHub Desktop.
Save yookoala/d97f3b3e67cd6769563255b214ffd54f to your computer and use it in GitHub Desktop.
The simplest syntax to do swaping in PHP
<?php
/**
* This works.
*/
$a = 1; $b = 2;
echo "Before swap: {$a}, {$b}\n";
list($a, $b) = [$b, $a];
echo "After swap: {$a}, {$b}\n";
// result:
// Before swap: 1, 2
// After swap: 2, 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment