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)