: This article mainly introduces php variable exchange. if you are interested in the PHP Tutorial, you can refer to it.
// 1, for the number $ a = $ a + $ B; $ B = $ a-$ B; $ a = $ a-$ B; // 2, use the list structure $ a = 'a'; $ B = 'B'; var_dump ($ a, $ B); list ($ a, $ B) = array ($ B, $ a); var_dump ($ a, $ B); // 3, use an array $ a = 'a'; $ B = 'B'; var_dump ($, $ B); $ a = array ($ a, $ B); $ B = $ a [0]; $ a = $ a [1]; var_dump ($, $ B); // 4, replace $ a = 'A' with a string; $ B = 'B'; var_dump ($ a, $ B); $. = $ B; $ B = str_replace ($ B, '', $ a); $ a = str_replace ($ B,'', $ a); var_dump ($, $ B); // 5, use a string to intercept $ a = 'a'; $ B = 'BB'; var_dump ($ a, $ B); $. = $ B; $ B = substr ($ a, 0, strlen ($ B); $ a = substr ($ a, strlen ($ B )); var_dump ($ a, $ B); // 6, use explode $ a = 'a'; $ B = 'BB'; var_dump ($ a, $ B ); $. = '@@'. $ B; $ a = explode ('@', $ a); $ B = $ a [0]; $ a = $ a [1]; var_dump ($, $ B); // 7. use the XOR operation $ a = 'a'; $ B = 'BB'; var_dump ($ a, $ B ); $ a = $ a ^ $ B; $ B = $ B ^ $ a; $ a = $ a ^ $ B; var_dump ($ a, $ B );
The above introduces the php variable exchange, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.