Excuse me, smarty only outputs an array of methods without loops.

Source: Internet
Author: User
Ask smarty to output only one array method, without looping $ arr = array (); $ arr [0] = & quot; 1 & quot ;; $ arr [1] = & quot; 2 & quot; $ arr [2] = & quot; 3 & quot; $ arr [0] = & quot; 4 & quot; smarty-& gt ask smarty to output only one of the array methods, without loops
$ Arr = array ();
$ Arr [0] = "1 ";
$ Arr [1] = "2 ";
$ Arr [2] = "3 ";
$ Arr [0] = "4 ";

Smarty-> assign ("a1", $ arr );


In the htm template file, how can I output only one of the arrays? I know that foreach can be used to display them cyclically, but I only need to display one.

Hope to answer.

------ Solution --------------------
PHP code
$ Arr = array (); $ arr [0] = "1"; $ arr [1] = "2"; $ arr [2] = "3 "; $ arr [0] = "4"; foreach ($ arr as $ key => $ val) {if ($ key = "what you want to output ") {smarty-> assign ("a1", $ arr [$ key]) ;}}
------ Solution --------------------
Top
------ Solution --------------------
{$ A1.0} or {$ a [0 ]}
------ Solution --------------------
{$ A1.0} or {$ a1 [0]}
------ Solution --------------------
Study!
------ Solution --------------------
{$ A1.0}. in this way, you need to remember the subscript of the array, which is inconvenient.
{$ A1 [0]} is incorrect.
------ Solution --------------------
Is it random? Shuffle ($ a1)

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.