Home >Backend Development >PHP Tutorial >Detailed explanation of ThinkPHP's N method example_PHP tutorial
ThinkPHP’s 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:
N('Counting position'[,'Step value'])
For example, if we want to count the number of queries on the page, we can use
N('read',1);
means that each time execution reaches this position, the counter will be incremented 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.