&引用变量的有关问题

WBOY
Release: 2016-06-13 13:36:27
Original
809 people have browsed it

&引用变量的问题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->

function _is_numerice($var)
{
    if(is_numeric($var))
    {
        return true;
    }
}

$var = 123456;

_is_numerice($var); 

_is_numerice(&$var);  //此处使用&, 是否增加了效率?


Copy after login


------解决方案--------------------
这样增加了效率
PHP code
function _is_numerice(&$var)
<br><font color="#e78608">------解决方案--------------------</font><br>这么小的变量引用效率几乎没什么差别吧。数据量大的时候可能就有些提高。<br><br>还有怎么不直接 is_numeric($var) 了得。怎又写个函数又套了一下。
<br><font color="#e78608">------解决方案--------------------</font><br>1、由于只改变了变量的传递方式,并没有改变运算逻辑,所以只考虑内存的使用情况<br>
Copy after login
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);  //此处使用&, 是否增加了效率?
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨

(⊙o⊙)…。 是这样的, is_numerice只是个简单例子,里面还有好多分析代码的。

function _is_numerice(&$var) 和直接使用 _is_numerice(&$var) 用什么区别吗?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!