Home  >  Article  >  Backend Development  >  ThinkPHP之N方法实例详解_php实例

ThinkPHP之N方法实例详解_php实例

WBOY
WBOYOriginal
2016-05-17 08:41:27780browse

ThinkPHP的N方法属于计数器方法,被用于核心的查询、缓存统计的计数和统计。但是其实可以用于应用的其他计数用途,用法比较简单,调用格式:

N('计数位置'[,'步进值'])

例如,我们要统计页面中的查询次数,可以用

N('read',1);

表示每次执行到该位置都会引起计数器加1,到页面结束之前,我们就可以用

$count = N('read');

来统计当前页面执行的查询数目。
如果你希望计数器每次增加5,那么可以改变步进值,例如:

N('score',5);

需要注意的是,N方法页面执行完毕后的统计结果不会带入下次统计。

Statement:
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