|
可变变量
$a = 'name';
$$a = '张三';
即等价于
$name = '张三';
定义常量
define('PI', 3.14);
执行操作符
$out = `ls -la`;
echo $out;
类型操作符instance
if($myobject instanceof sampleClass) {
echo "myobject is an instance of sampleClass";
}
函数number_format使用
$totalmount = 123.4567;
echo number_format($totalmount, 2);
函数gettype()和settype()
$a = 100;
echo gettype($a) . "<br \>";
settype($a, 'double');
echo gettype($a) . "<br \>";
测试函数
is_array(): 是否为数组
is_double(),is_float(),is_real():是否为浮点数
is_long(),is_int(),is_integer():是否为整数
is_string():是否为字符串
is_bool():是否为布尔值
is_object():是否是一个对象
is_resource():是否是一个资源
is_null():是否为null
is_scalar():是否为一个标量,即,一个整数、布尔值、字符串、浮点数
is_numeric():是否为数字或数字字符串
is_callable():是否为有效的函数名
isset():如果变量存在,则返回true,否则返回false
unset():销毁一个变量
empty():用来检查一个变量是否存在,以及它的值是否为非空和非0,相应的返回值为true或false
变量重解释
int intval()
float floatval()
string strval()
declare指令
一般用于性能测试调试
打开文件
函数fopen()
$fp = fopen('d:/tmp/test.txt','ab');
注:可以打开远程文件,通过ftp或http打开文件
写文件
函数fwrite()、fputs()(是fwrite()的别名函数)
在php5中可以使用
file_put_contents(),与之对应的是file_get_contents()函数
读文件
函数fgets()、fgetss()、fgetcsv()、readfile()、fpassthru()和file()、
fgetc()、fread()
$fp = @fopen("d:/work/tmp/a.txt","rb");
while(!feof($fp)) {
$line = fgets($fp, 4096);
echo $line . "<br />";
}
函数feof()作为文件结束的判断条件
查看文件是否存在的函数:file_exists()
查看文件大小的函数:filesize()
删除一个文件的函数:unlink()
在文件中定位的函数:rewind()、fseek()、ftell()
文件锁定函数:flock()
注:关于更多的文件操作内容,参考http://www.php.net/filesystem
格式化数字函数number_format
$number = 1234567.8765432;
echo $numer_format($number, 2, '.', ',');
array_walk()函数
示例:
<?php
$arr = array(1,2,3,4,5);
function my_multiply(&$value, $key, $factor) {
$value *= $factor;
}
array_walk($arr, 'my_multiply', 30);
foreach($arr as $item) {
echo $item . " ";
}
?> |
|
|