PHP 函数
添加时间:2013-7-1 点击量:
字符串函数:
1 ¥name = fakeface;
2 ¥myname =substr(¥name,0,3);//输出前面三个字符 fak
3 print ¥myname;
4 ¥name = strtoupper(¥name); //小写
5 print ¥name;
6 ¥name = strtolower(¥name);、、大写
7 print ¥name;
8 ¥position = strpos(¥name,c);//输出c的地位
9 print ¥position;
View Code
数学函数:
1 ¥num = 123.123456;
2 print round(¥num);//输出一个整数123
3 print round(¥num,3);//输出数字并保存三位小数123.123
4 rand(1,10);//在1,10随机生成一个数字
数组函数:
1 ¥fav_bands = array();
2 array_push(¥fav_bands, Maroon 5);//给数组添加元素
3 array_push(¥fav_bands, Bruno Mars);
4 array_push(¥fav_bands, Nickelback);
5 array_push(¥fav_bands, Katy Perry);
6 array_push(¥fav_bands, Macklemore);
7 print count(¥fav_bands); 查看数组有几许元素
8
9
10 ¥names = array(david,alana,violet,rory);
11 sort(¥names);// array(alana,david,rory,violet)
12 print join(, , ¥names);// prints alana, david, rory, violet
13 rsort(¥names); // array(violet,rory,david,alana)
字符串函数:
1 ¥name = fakeface;
2 ¥myname =substr(¥name,0,3);//输出前面三个字符 fak
3 print ¥myname;
4 ¥name = strtoupper(¥name); //小写
5 print ¥name;
6 ¥name = strtolower(¥name);、、大写
7 print ¥name;
8 ¥position = strpos(¥name,c);//输出c的地位
9 print ¥position;
View Code
数学函数:
1 ¥num = 123.123456;
2 print round(¥num);//输出一个整数123
3 print round(¥num,3);//输出数字并保存三位小数123.123
4 rand(1,10);//在1,10随机生成一个数字
数组函数:
1 ¥fav_bands = array();
2 array_push(¥fav_bands, Maroon 5);//给数组添加元素
3 array_push(¥fav_bands, Bruno Mars);
4 array_push(¥fav_bands, Nickelback);
5 array_push(¥fav_bands, Katy Perry);
6 array_push(¥fav_bands, Macklemore);
7 print count(¥fav_bands); 查看数组有几许元素
8
9
10 ¥names = array(david,alana,violet,rory);
11 sort(¥names);// array(alana,david,rory,violet)
12 print join(, , ¥names);// prints alana, david, rory, violet
13 rsort(¥names); // array(violet,rory,david,alana)