PHP - Swap The Values of 2 Variables Without Temp Variable 2023

By XiaoXin
A Bit Randomly

The biggest advantage of KestrelServer is its cross-platform capability. If the ASP.NET CORE application only needs to be deployed in the Windows environment, IIS is also a good choice. ASP.NET CORE applications have two d... Read Two deployment modes of ASP.NET Core with IIS

Main Contents

PHP - Swap The Values of 2 Variables Without Temp Variable

// 1 list($a, $b) = array($b, $a);

// 2 $a = $a . $b; 
$b =  strlen($b); 
$b = substr ($a, 0, (strlen($a) – $b)); 
$a = substr ($a, strlen($b)); 

// 3 (Must use a character that cannot appear in both strings as a separator)
$a = $b .','. $a;
$a = explode (',', $a); 
$b = $a[1];
$a = $a[0];

// 4 This is when both numbers are numbers: 
$a = $a + $b;
$b = $a – $b;
$a = $a – $b;

// 5 with array
$a = array ($a, $b); 
$b = $a[0];
$a = $a[1];  

Continuing...

Please Share This Article Thank You!

Parts of Top Latest PHP Interview Questions And Answers For Experienced
What is PHP heredoc used for?

Heredoc is generally not described in detail in formal PHP documentation and technical books. It is a Perl-style string output technique. Using heredoc technology can realize the quasi-separation of interface and code, suc...

The difference of echo, print(), print_r(), sprintf(), var_dump() in PHP

1: echo: the statement is not a function, there is no return value, and multiple variable values ​​can be output without parentheses. Arrays and objects cannot be output, only simple types (such as int, string) can be prin...