Write a program to swap two numbers using php.



Write a program to swap two numbers using php...

Answer / Aqib Ashhar

Here's a simple PHP script that swaps the values of two variables:

```php
$num1 = 10;
$num2 = 20;

// Swap the values
$temp = $num1;
$num1 = $num2;
$num2 = $temp;

echo "Num1: {$num1}n";
echo "Num2: {$num2}";
```
This script first stores the value of `$num1` in a temporary variable, then assigns the value of `$num2` to `$num1`, and finally assigns the value of the temporary variable (previously containing `$num1`) to `$num2`. The final output will be:

```
Num1: 20
Num2: 10
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

Explain the differences between get and post methods?

1 Answers  


what is Opern source?

3 Answers  


Is php used for frontend or backend?

1 Answers  


Why php script is not running in browser?

1 Answers  


What and How possible injection in PHP and mysql?

3 Answers   RedAlkemi,


How many days will it take to learn php?

1 Answers  


What is a query in a database?

1 Answers  


How can we determine whether a variable is set?

1 Answers  


What is the use of pear in php?

1 Answers  


What does a special set of tags do in php?

1 Answers  


What is cookie in php with example?

1 Answers  


How is it possible to parse a configuration file?

1 Answers  


Categories