前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >开发常用知识点

开发常用知识点

作者头像
wangxl
发布2018-03-07 11:03:35
7220
发布2018-03-07 11:03:35
举报
文章被收录于专栏:PHP在线PHP在线

php允许传递任意个参数:

function getArg($a="",$b=""){ echo "one:".$a."<br/>"; echo "two".$b; }

getArg(100,200);

调用函数结果:

one:100

two:200

  • PHP的不定参数用法,其使用到了 func_get_args()方法

function foo() {

// 取得所有的传入参数的数组

$args = func_get_args();

foreach ($args as $k => $v) {

echo “arg”.($k+1).”: $v\n”;

}

}

foo();

/* 什么也不会输出 */

foo(‘hello’);

/* 输出

arg1: hello

*/

foo(‘hello’, ‘world’, ‘again’);

/* 输出

arg1: hello

arg2: world

arg3: again

*/

使用glob()查找文件

// 取得所有的后缀为PHP的文件 $files = glob(‘*.php’); print_r($files); 输出: Array ( [0] => phptest.php [1] => pi.php [2] => post_output.php [3] => test.php )

你还可以查找多种后缀名:

// 取PHP文件和TXT文件 $files = glob(‘*.{php,txt}’, GLOB_BRACE); print_r($files); /* 输出: Array ( [0] => phptest.php [1] => pi.php [2] => post_output.php [3] => test.php [4] => log.txt [5] => test.txt )

$files = glob(‘../images/a*.jpg’); // applies the function to each array element $files = array_map(‘realpath’,$files); print_r($files); /* output looks like: Array ( [0] => C:\wamp\www\images\apple.jpg [1] => C:\wamp\www\images\art.jpg ) */

其实PHP中自带一个函数来生成唯一的id,这个函数就是uniqid()。下面是用法:

echo uniqid(); /* 输出 4bd67c947233e */

字符串压缩

当我们说到压缩,我们可能会想到文件压缩,其实,字符串也是可以压缩的。PHP提供了 gzcompress() 和gzuncompress() 函数

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2014-10-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 php 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用glob()查找文件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档