Php variable exchange

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.