Skip to content

Instantly share code, notes, and snippets.

@yookoala
Created August 13, 2020 07:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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