现在有一个二维数组如下:
$student = Array
(
    [id] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
            [4] => 5
        )    [name] => Array
        (
            [0] => zhangsan
            [1] => lisi
            [2] => wangwu
            [3] => liwu
            [4] => maliu
        )    [notes] => Array
        (
            [0] => good
            [1] => bad
            [2] => best
            [3] => good
            [4] => good
        )
)我现在想用smarty模板引擎中创建模板student.tpl
显示出如下的内容:
id name notes
1  zhangsan  good
2  lisi  bad
3  wangwu   best
4  liwu  good
5  maliu  good通过section 或者foreach 在模板中如何实现?

解决方案 »

  1.   

    数据设计逻辑上有问题!针对现在这个,先list($id,$name,$notes) = $student;再循环其中某一个去取值
      

  2.   

    $student = Array(
     "id" => $stu_id,
     "name" => $stu_name,
     "notes" => $stu_notes
    );tpl如下:
    id name notes
    {foreach from=$student id=key_id item=val}
       {$val.id} {$val.name} {$val.notes}
    {/foreach}以上。
    不要人为割裂整体信息,这也算面向对象的思维了吧
      

  3.   

    写错了
    $student = array();
    $student[] = Array(
     "id" => $stu_id,
     "name" => $stu_name,
     "notes" => $stu_notes
    );
      

  4.   

    楼上的 $student = array();
    $student[] = Array(
     "id" => $stu_id,
     "name" => $stu_name,
     "notes" => $stu_notes
    );这里的 $stu_id 是怎么回事?
      

  5.   

    就没个人能完完整整写出来吗?我怎么给分啊?
    $smarty->assign($stu,...)    这地方用$student数组还是用你说的$student[]???
    我试了 直接不行。
      

  6.   

    我来给你回,仅参考:
    PHP中,先做:
    list($id,$name,$notes) = $student;
    ...->assign('st_id',$id);
    ...->assign('st_name',$name);
    ...->assign('st_notes',$notes);模板中:(前提是:$id,$name,$notes的元素个数一样)
    {foreach from=$st_id key=id item=val}
      {$val}    {$st_name[$id]}    {$st_notes[$id]}
    {/foreach}