Home>Article>PHP Framework> How to use n method in thinkphp

How to use n method in thinkphp

WBOY
WBOY Original
2022-03-07 10:39:35 2198browse

In thinkphp, the n method belongs to the counter method, which is used for core queries, cache statistics, and statistics. The syntax is "N('counting position'[,'step value'])"; n The statistical results after the method page is executed will not be carried over to the next statistics.

How to use n method in thinkphp

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

How to use the n method in thinkphp

The N method is a counter method and is used for core queries, cache statistics and statistics. But it can actually be used for other counting purposes in the application. The usage is relatively simple. The calling format is:

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

. For example, if we want to count the number of queries on the page, we can use

N('read',1);

to indicate that each execution This position will cause the counter to increase by 1. Before the end of the page, we can use

$count = N('read');

to count the number of queries executed on the current page.

If you want the counter to increase by 5 each time, you can change the step value, for example:

N('score',5);

It should be noted that the statistical results after the N method page is executed will not be carried over to the next statistics.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to use n method in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

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