php使用到的函数记录一

226 阅读1分钟

1、mkdir()创建多级目录的时候需要将第三个参数设置为true

  • 说明bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

2、strtotime() add months

$birthdate  = "2010-1-1";
//6个月之后的时间
$waydate    = date('Y-m-d', strtotime('+6 months', strtotime($birthdate)));

3、array_search()

array_search — 在数组中搜索给定的值,如果成功则返回首个相应的键名

4、sprintf

sprintf — Return a formatted string

echo sprintf("%'.9d\n", 123); //......123
echo sprintf("%'.09d\n", 123);//000000123
echo sprintf("%1$09d\n", 123);//000000123
echo sprintf("09d\n", 123);//000000123

5、str_pad

str_pad — 使用另一个字符串填充字符串为指定长度

$input = "Alien";
echo str_pad($input, 10);                      // 输出 "Alien     "
echo str_pad($input, 10, "-=", STR_PAD_LEFT);  // 输出 "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH);   // 输出 "__Alien___"
echo str_pad($input,  6, "___");               // 输出 "Alien_"
echo str_pad($input,  3, "*");                 // 输出 "Alien"

6、iconv解决中文排序问题

$collection->sortBy(function ($item) {
                return iconv('utf8','GBK',$item->name);
            })->values();