在 smarty 中显示多维数组元素
可能的重复:
在 smarty 中显示数组元素
我合并了两个 mysql 结果:
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"
}
}
我应该在 smarty 中显示它们,所以:
assign_values('rand_pro',$resN);
现在我尝试像这样在 smarty 中显示:
{foreach name=outer item=pro from=$rand_pro}
{foreach key=key item=item from=$pro}
{$key}: {$item}<br />
{/foreach}
{/foreach}
它按顺序显示结果。我需要提取某些位置的值。那么如何提取值,例如名字、姓氏等?
Possible Duplicate:
Display array elements in smarty
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)
shows the following result :
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_pro',$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 ?
{$item.bz_pro_last_name}
{$key.bz_pro_first_name}
不确定我是否收到您的问题,但请在循环中尝试上述操作。
{$item.bz_pro_last_name}
{$key.bz_pro_first_name}
Not sure if I got your question but try the above inside your loop.