在smarty中显示数组元素 [英] Display array elements in smarty

查看:125
本文介绍了在smarty中显示数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我合并了两个mysql结果:

I have merged two mysql results :

while($rs_1 = mysql_fetch_array($r1))
{
    $arr1[] = $rs_1;
}

while($rs_2 = mysql_fetch_array($r2))
{
    $arr2[] = $rs_2;
}

$resN = array_merge($arr1,$arr2);

var_dump($resN)显示以下结果:

array(5) { 
    [0] => array(4) { 
        [0] => string(6) "Petric" 
        ["bz_pro_first_name"] => string(6) "Petric" 
        [1] => string(8) "Naughton" 
        ["bz_pro_last_name"] => string(8) "Naughton" 
    } 
    [1] => array(4) { 
        [0] => string(6) "Nitish" 
        ["bz_pro_first_name"] => string(6) "Nitish" 
        [1] => string(12) "Dolakasharia" 
        ["bz_pro_last_name"] => string(12) "Dolakasharia" 
    } 
    [2] => array(4) { 
        [0] => string(6) "Martin" 
        ["bz_pro_first_name"] => string(6) "Martin" 
        [1] => string(3) "Rom" 
        ["bz_pro_last_name"] => string(3) "Rom" 
    } 
    [3] => array(4) { 
        [0] => string(5) "Steve" 
        ["bz_pro_first_name"] => string(5) "Steve" 
        [1] => string(5) "Wough" 
        ["bz_pro_last_name"] => string(5) "Wough" 
    } 
    [4] => array(4) { 
        [0] => string(3) "Liz" 
        ["bz_pro_first_name"] => string(3) "Liz" 
        [1] => string(6) "Hurley" 
        ["bz_pro_last_name"] => string(6) "Hurley" 
    }
}

我应该巧妙地展示它们:

I am supposed to display them in smarty so :

assign_values('rand_ad',$ resN);

assign_values('rand_ad',$resN);

现在,我试图像这样聪明地展示:

Now I tried to display in smarty like this :

{foreach name=outer item=pro from=$rand_pro}
    {foreach key=key item=item from=$pro}
        {$key}: {$item}<br />
    {/foreach}
{/foreach}

它按顺序显示结果.我需要提取某些位置的值.那么如何提取值,例如名字,姓氏等?

It displays the results but serially. I need to extract the values in some positions . So how can I extract the values eg first name, last name etc ?

推荐答案

您没有给出所需输出的示例,所以我会猜测一下.假设您正在寻找上面的数组的以下输出:

You didn't give an example output of what you wanted, so I'll take a guess. Assuming you are looking for the following output for the array above:

0: Petric Naughton<br />
1: Nitish Dolakasharia<br />
2: Martin Rom<br />
3: Steve Wough<br />
4: Liz Hurley<br />

您可以这样做:

{foreach from=$rand_pro item=pro key=pro_key}
    {$pro_key}: {$pro.bz_pro_first_name} {$pro.bz_pro_last_name}<br />
{/foreach}

如果我的假设不正确,请使用您期望更加清晰的输出来更新您的问题.

If I am assuming incorrectly, please update your question with the output you are expecting to be more clear.

这篇关于在smarty中显示数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆