时间:2021-07-01 10:21:17 帮助过:28人阅读
?
?
"); /* * 数据类型转换:强制转换 * gettype():获取某个变量的类型,返回值是一个类型字符串 */ $sum = 25.6; echo gettype($sum); $count = (int) $sum; echo gettype($count); echo ($count); echo ("
"); echo ("
"); /* * settype(): 设置变量类型,返回值是一个boolean,是否设置成功 */ echo ("
"); $num1 = 100; echo settype($sum1, "string"); // boolean, integer, float, array, object, null echo ("
"); echo $num1; echo ("
"); echo ("----------------------------------"); echo ("
"); /* * isset(变量名, 变量名..): 判断某个变量是否存在 * unset(变量名, 变量名...): 销毁某个变量 */ $num2 = 12.58; $num3 = 12; echo isset($num2, $num3); echo isset($num3); unset($num2, $num3); echo isset($num2); echo isset($num1); echo isset($num1, $num3); echo ("
"); echo ("----------------------------------"); echo ("
"); /** * empty(变量名): 判断某个变量是否为空 * 若为空则返回1,非空则返回0 * null, 0, "", "0", false, array(), var $var以及没有任何属性对象都会被看成null */ $num4 = 12.4; $num5 = ""; $num6 = (boolean)0; $num7 = null; echo (empty($num4)); echo (empty($num5)); echo (empty($num6)); echo (empty($num7)); echo ("
"); echo ("----------------------------------"); echo ("
"); /** * 以上为判断是否属于变量是否属于某种类型 * 若是则返回ture,否则返回false */ echo is_double($num4); echo is_float($num4); echo is_int($num4); echo is_long($num4); echo is_null($num4); echo is_object($num4); echo is_array($num4); echo is_string($num4); echo ("
"); echo ("----------------------------------"); echo ("
"); /* * 临时转换变量 * intvar()、floatvar()、strvar() :临时转换变量类型为int、float、string */ $num8 = 10.1; echo gettype($num8); echo intval($num8); echo gettype(intval($num8)); echo floatval(intval($num8)); echo gettype(floatval(intval($num8))); echo strval($num8); echo gettype(strval($num8)); echo gettype($num8); echo ("
"); echo ("----------------------------------"); echo ("
"); //定义常量,常量定义后其值不能在发生改变 define("TOTAL", 23); echo TOTAL; //PHP预设常量,定义在phpinfo()函数里面 echo phpinfo(); echo ("
"); echo $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"]; ?>
?
?表单处理:
?
"; echo "您输入的密码是:".$pwd; ?>?
: 在浏览器网页前台显示有效,后台源代码中显示无效 * 转义字符:在前台浏览器中显示无效。在后台源代码中显示有效 * 转义字符: * \n : 换行符 * \r : 回车符 * \t : 水平制表符 * \\ : 反斜杠 * \$ : 美元字符 * \" : 双引字符 */ $username = "shma"; $username2 = "马韶华"; echo "His name is $username"; echo '?
'; echo 'His name is $username'; echo "
"; echo "他的名字是$username2,他已经23岁了!"; //无法显示 echo "
"; echo "他的名字是".$username2.",他已经23岁了!"; echo "
"; echo "他的名字是".$username2.",\n他已经23岁了!"; echo "
"; echo '他的名字是".$username2.",\n他已经23岁了!'; /* * == 与 === * != 与 !== * 恒等表示只有两个操作数相等并且类型相同时才相等,或者不等 */ $a = 6; $b = 5; $c = "5"; echo '
'; echo $a == $b; echo $a != $b; echo $a === $b; echo $a !== $b; echo $c === $b; echo $c == $b; // 错误抑制操作符 @ $num = @(10/0); echo "$num"; $value = 10; echo "value = ".($value > 1 ? $value : "0"); // 数学运算 /* * + : 数字之间运算 * . : 字符串之间运算 */ $a1 = 'a'; $b1 = 5 .$a1; echo $b1; // is_numeric ― 检测变量是否为数字或数字字符串 $a = 123; if(is_numeric($a)) { echo $a."是数字"; } else { echo $a."不是数字"; } echo "
"; // 获取随机数 echo rand(); echo "
"; echo rand(1, 10); echo "
"; echo mt_rand(); echo "
"; echo mt_rand(1, 10000); echo "
"; echo getrandmax(); echo "
"; echo mt_getrandmax(); //格式化数据 $a = 10324.564343; echo "
"; echo "
"; echo number_format($a); echo number_format($a,2); echo number_format($a,2,"#", "!"); //数学运算 $b = -6.3; echo abs($b); echo min(1,3,4,5,6,-5); echo max(1,3,4,5,6,-5); ?>
?