Is there a problem with array_map-php using too much reference?

Source: Internet
Author: User
{Code ...} recently, too many array_map functions are used to process data in place of foreach, and writing too many references using anonymous functions and references (& amp;) will this cause php performance problems?
array_map(function($item) use(&$i, &$tmpVar) {                $i++;                $tmpVar['t'.$i] = $item;            }, $ct_info);            

In the recent project, too many array_map replace foreach to process data, and anonymous functions and references are used (&)
Write too muchReferenceWill it cause php performance problems?

Reply content:
array_map(function($item) use(&$i, &$tmpVar) {                $i++;                $tmpVar['t'.$i] = $item;            }, $ct_info);            

In the recent project, too many array_map replace foreach to process data, and anonymous functions and references are used (&)
Write too muchReferenceWill it cause php performance problems?

It will not affect you. We recommend that you take a look at "deep understanding of the PHP kernel". In the interpreterzvalStruct stores the information of the variable. The reference of the variable is that the symbol table points to the samezvalOnly one record.

Http://www.php-internals.com/book? P = chapt03/03-01-00-variables-structure

Using references will not cause performance problems, but misuse of references when you are not familiar with references may easily cause some strange errors, and these errors are generally difficult to troubleshoot.

Let me add some clear answers:

However, misuse of references may cause some strange errors when you are not familiar with references, and these errors are generally difficult to troubleshoot.

For example:


   $v){        $v = &$arr[$k];    }    var_dump($arr);?>

@ SyuTingSong
The PHP kernel saves variables on the one hand.
In addition, when PHP is running as a web program, it will always release variable references and so on at the end of the request. Therefore, a few more references are irrelevant.

Thank you for your failure to fully adopt it.

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.