开发者社区> 问答> 正文

html标签如何使用php中的变量

html标签中使用php变量,提示:Undefined index: uid in /var/www//list.php
,list.php的具体代码如下:

<?php

    require 'redis.php';
    for ($i=0; $i <= ($redis->get("userid")) ; $i++)
    {
        $data[] = $redis->hgetall("user:".$i);
    }
    /* var_dump($data) 的结果如下:
    array (size=3)
  0 => 
    array (size=0)
      empty
  1 => 
    array (size=4)
      'uid' => string '1' (length=1)
      'username' => string 'jjj' (length=3)
      'password' => string '123' (length=3)
      'age' => string '20' (length=2)
  2 => 
    array (size=4)
      'uid' => string '2' (length=1)
      'username' => string 'lamp' (length=4)
      'password' => string '123' (length=3)
      'age' => string '20' (length=2)
      */
?>

<table border="1">
    <caption>user list</caption>
    <tr>
        <th>uid</th>
        <th>username</th>
        <th>age</th>
    </tr>
    <?php foreach ($data as $v) {?>

    <tr>
        <td><?php echo $v['uid'] ?></td>
        <td><?php echo $v['username'] ?></td>
        <td><?php echo $v['age'] ?></td>
    </tr>
    <?php } ?>
</table>

展开
收起
杨冬芳 2016-06-23 15:10:42 2994 0
1 条回答
写回答
取消 提交回答
  • IT从业

    echo 前 isset 下不就可以了吗

    2019-07-17 19:46:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PHP与APM_技术内幕和最佳实践 立即下载
阿里云栖开发者沙龙PHP技术专场-静态扫描为你的项目上线保驾护航-周梦康 立即下载
天猫HTML5互动技术实践 立即下载