html标签使用php中的变量方法如下:
一、如果html标签中使用php变量,提示:Undefined index: uid in /var/www//list.php ,list.php的具体代码如下:
<?phprequire '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>
这时在echo 前 isset 下就可以了,代码如下:
<?php $a = 10 if( isset($a) ) { echo"这个变量存在" } else{echo"这个变量不存在" }?>二、 php 可以和html混编的 ,如下图所示
没有静态变量的说法,只有局部变量和全局变量。要类似静态变量的功能,可以通过如下方式定义:
1、定一个全局对象
var obj = {}
2、在全局对象中增加属性
obj.CONST_A='KKKK'//增加一个属性CONST_A
3、当做静态变量使用
在任何地方都可以直接使用obj.CONST_A表示字符串KKKK