Skip to content

Instantly share code, notes, and snippets.

@ctkqiang
Created February 11, 2025 11:24
Show Gist options
  • Save ctkqiang/f45ef63746674c974cb4ef21b0fd9da7 to your computer and use it in GitHub Desktop.
Save ctkqiang/f45ef63746674c974cb4ef21b0fd9da7 to your computer and use it in GitHub Desktop.
// For Javascript I use (commonJS)
const swapNumber = (a, b) => {
let temp = a;
a = b;
b = temp;
return [a, b];
};
// Execution:
const num1 = 20;
const num2 = 30;
[num1, num2] = swapNumber(num1, num2);
console.log(num1);
console.log(num2);
// ----------
// My ans for php
function swapNumber($a, $b) {
$temp = $a;
$a = $b;
$b = $temp;
return array($a, $b);
}
// Call func
$a = 20;
$b = 30;
list($firstNum, $secondNum) = swapNumber($firstNum, $secondNum);
echo $firstNum."\n";
echo $secondNum;
@ctkqiang
Copy link
Author

No worries, after the interview , this gist will be deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment