Explore how to get the length of an array in Smarty and a detailed _php tutorial on Smarty calling PHP functions

Source: Internet
Author: User
How to get the length of an array in Smarty
Premise hypothesis:
An array of arrays is assigned to smarty, assuming that the smarty delimiter is ' {' and '} '.
As you can see from a lot of data, when you ask for the length of an array in smarty, you use the method call that is added |count after the array. That is, the length of the array is obtained by {array|count}. But today when I write a template, I find that this does not get the length of the array, but just a return string array. This means that only the result of {array} is returned, and the length of its array is not returned.

Looking at the Smarty\plugins folder, there is no related method for count, that is, Count is a direct call to the method in PHP.
Later, through the data on the network, it is found that you can add @ in front of Count to get the length of the array correctly. Further look at the source code of the smarty, found that smarty on the property regulator behind the method name processing, the front plus @ will be special treatment. so make a decision: When you invoke a function defined in PHP in a property conditioner in Smarty, you can express it by adding @.

1, when the type of the array of methods to test, found that no @ symbol will be error. 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 {array| @end} when you call the end method to get the last set of data for the arrays.
2, in the string of related functions to test, found that add not add @ can be normal call.
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 decided that the template is the interface design personnel, if too many complex logic, for them is a kind of torture.


http://www.bkjia.com/PHPjc/327747.html www.bkjia.com true http://www.bkjia.com/PHPjc/327747.html techarticle how to get the length of an array in Smarty assumptions: An array of arrays is assigned to smarty, assuming that the smarty delimiter is ' {' and '} '. In a lot of information, we can see that in Smarty ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.