How to get the length of an array in Smarty
Premise hypothesis:
An array of arrays is assigned to smarty, assuming that the Smarty's delimiters are ' {' and '} '.
As you can see in a lot of data, the length of the array is required in the smarty, and the |count method call is used after the array. The length of the array is obtained through {array|count}. But today, when writing a template, you find that you don't get the length of the array, just the string array that's returned. That is, it simply returns the result of the {array} and does not return the length of its array.
Looking at the Smarty\plugins folder, I found that there was no method for count, that is, Count is a direct call to the method in PHP.
Later, through the data on the network, it was found that you can add @ before count to get the correct length of the array. Further look at the source code of Smarty, found that the smarty of the property adjuster after the method name processing, will be the front plus @ for special treatment. so make a judgment: when you call a defined function in PHP in the property adjuster in Smarty, you can express it by adding @.
1. When testing a method that is an array of types, it is found that no @ symbol can be faulted. For example, to call the Count method on an array to find the length of the array, you can call {array| @count}, and you can pass the {array| @end} if you want the last set of data to be derived from the arrays by calling the end method.
2, in the relevant function of the string test, found that the addition of @ can be normal calls.
3, the other has not been carefully tested. It is not encouraged to invoke complex PHP functions in Smarty, because Smarty's intention is to implement code and template separation, it should be recognized that the template is the interface design personnel, if too many complex logic, for them is a kind of torture.