Created
February 11, 2025 11:24
-
-
Save ctkqiang/f45ef63746674c974cb4ef21b0fd9da7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No worries, after the interview , this gist will be deleted.