PHP变量引用与动态变量机制
代码示例如下:
<?php
// 引用赋值示例
$one="test";
$two=&$one; // 此处为引用赋值,两个变量共享同一内存地址
// 动态变量(可变变量)示例
$one="######";
$two="one";
$three="two";
echo $three."<br>"; // 输出结果为 "two"
echo $$three."<br>"; // 输出结果为 "one"
echo $$$three."<br>"; // 输出结果为 "######"
// PHP语言中共包含8种数据类型
// 4种标量类型:int (integer)
// bool (boolean)
// float, double, real
// string
// 2种复合类型:array
// object
// 2种特殊类型:resource (资源类型)
// null (空类型)
// 整数的声明方式
$int=10; // 十进制声明
$int=045; // 八进制声明
$int=0xff; // 十六进制声明
$float=3.14E+5; // 科学计数法表示
$float=3.14E-5;
// 以下情况在布尔上下文中均被视为 false
$bool=false;
$bool=0;
$bool=0.000;
$bool=null;
$bool="";
$bool=" ";
$bool="0";
$bool=array();
// 字符串的声明方法
// 1. 单引号和双引号均可用于声明字符串
// 2. 声明的字符串长度无限制
// 3. 双引号字符串可直接解析变量,并支持转义字符(可转义单引号自身及反斜杠\)
// 4. 单引号字符串不支持变量解析,也不识别转义字符
// 5. 双引号内不能直接嵌套双引号,单引号内不能直接嵌套单引号
// 6. 推荐优先使用单引号以提升性能
$str='aaaaa';
$str="aaaa";
// 使用定界符声明字符串,适用于大段文本
// test为自定义标识符,其前后不得有任何字符或空格
// 结束标记也需以test开头且前无其他字符
$str=<<<test
this write content......
test;
>