// 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;