Created
February 11, 2025 11:24
-
-
Save ctkqiang/f45ef63746674c974cb4ef21b0fd9da7 to your computer and use it in GitHub Desktop.
Revisions
-
ctkqiang created this gist
Feb 11, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ // 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;