简体   繁体   中英

PHP results not displayed in smarty template

I have a variable $my_arr whose var_dump($my_arr) value is

array(3) { [0]=> object(stdClass)#6 (9) { ["prod_index"]=> string(1) "1" ["prod_code"]=> string(4) "amp1" ["prod_name"]=> string(11) "Amplifier A" ["prod_price"]=> string(6) "100.00" ["frequency"]=> string(1) "2" ["gain"]=> string(1) "2" ["gain_variation"]=> string(3) "0.2" ["noise"]=> string(1) "2" ["power"]=> string(2) "10" } [1]=> object(stdClass)#7 (9) { ["prod_index"]=> string(1) "3" ["prod_code"]=> string(4) "amp1" ["prod_name"]=> string(13) "Amplifire1.33" ["prod_price"]=> string(6) "133.00" ["frequency"]=> string(4) "2.12" ["gain"]=> string(1) "2" ["gain_variation"]=> string(3) "0.2" ["noise"]=> string(1) "2" ["power"]=> string(2) "10" } [2]=> object(stdClass)#8 (9) { ["prod_index"]=> string(1) "4" ["prod_code"]=> string(4) "amp1" ["prod_name"]=> string(13) "Amplifier1.45" ["prod_price"]=> string(6) "150.00" ["frequency"]=> string(4) "2.99" ["gain"]=> string(1) "2" ["gain_variation"]=> string(3) "0.2" ["noise"]=> string(1) "2" ["power"]=> string(2) "10" } } 

In smarty I tried

{foreach name = fe1 item = k from = arr}
{$k->prod_index}    
{/foreach}

But it is not showing any result .

Assuming you're already assigning the array to smarty like:

$smarty->assign( "arr", $my_arr );

You need to use the "." syntax, like:

{foreach name = fe1 item = k from = arr}
{$k.prod_index}    
{/foreach}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM