<!--php嵌入HTML--><html><head> <title>day01</title></head><body><h2> <?php echo "Hello Php" ?></h2></body></html><?php/*$声明变量并赋值*/ $a = 10; $b = ‘Lemon‘; $c = ‘柠檬‘; $d = true; $f = 55.55; $key = $a; $a=$b=$c=$d="value";/* 显示数据类型 int:整型 sting:字符串 float :浮点型 一个汉字占3个字符长度*/ var_dump($a); var_dump($b); var_dump($c); var_dump($d); var_dump($f); var_dump($key); /*isset * 检测当前数据是否被初始化 * 数据不定义不会分配内存空间*/ $num; if(isset($num)){ echo"num被定义了"; }else{ echo"num没有被定义"; }echo"<br>"; /*unset:释放变量*/ $num2 = 10; unset($num2); if(isset($num2)){ echo"num2被定义了"; }else{ echo"num2没有被定义"; }echo"<br>"; /*empty * 判断是否为空*/ $num3 = ‘ ‘; if(empty($num3)){ echo"num3是空"; }else{ echo"num不是空"; } /*变量名大小写敏感*/ $name = ‘zhangsan‘; $NAME = ‘lisi‘; echo$name; echo"<br>"; echo$NAME;echo"<br>"; /*单引号里面全是字符串 * 双引号可解析变量*/ $net = "lemon"; $age = 18; /*双引号套单引号要加转移符*/ $string = "今天天气不错{$age}岁的{$net}出去\"玩\"了"; /*单引号套单引号要加转移符*/ $string2 = ‘今天天气不错{$age}岁的{$net}出\‘去\‘玩了‘; echo$string;echo"<br>"; echo$string2; echo"<br>"; /*两种拼接字符串的方法*/ $string4 = ‘今天天气晴朗‘; $string5 = ‘我们出去玩吧‘; $result = "{$string4}{$string5}"; echo$result;echo"<br>"; echo$string4.$string5;
时间: 2024-10-16 22:05:40