& Reference variable-php Tutorial

Source: Internet
Author: User
& Amp; variable reference PHPcodefunction_is_numerice ($ var) {if (is_numeric ($ var) {returntrue ;}}$ var123456; _ is_numerice ($ var ); _ is_numerice (& amp; $ var); use & amp; here to check whether the variable is referenced
PHP code
  Function _ is_numerice ($ var) {if (is_numeric ($ var) {return true ;}$ var = 123456; _ is_numerice ($ var ); _ is_numerice (& $ var); // used here &, does it increase efficiency?


------ Solution --------------------
This increases efficiency.
PHP code
Function _ is_numerice (& $ var)
------ Solution --------------------
There is almost no difference in the efficiency of such a small variable reference. When the data volume is large, it may increase.

Why is there no direct is_numeric ($ var. How can I write another function.
------ Solution --------------------
1. because only the transfer mode of variables is changed and the operation logic is not changed, only the memory usage is considered.
PHP code
Function _ is_numerice ($ var) {if (is_numeric ($ var) {echo memory_get_usage (), PHP_EOL; return true ;}$ var = 123456; echo memory_get_usage (), PHP_EOL; _ is_numerice ($ var); echo memory_get_usage (), PHP_EOL; _ is_numerice (& $ var); // is it more efficient to use & here?
------ Solution --------------------
Discussion

(⊙ O ⊙ ).... Yes. is_numerice is just a simple example. There are a lot of analysis code in it.

What is the difference between function _ is_numerice (& $ var) and directly using _ is_numerice (& $ var?

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.