汇总系列会坚持持续更新,时间有限的话会先记录相关内容,后期完善具体,只有点滴积累才能厚积薄发!

1、闭包函数

php的闭包(Closure)也就是匿名函数

$a =function()use($b) { 

}

2、preg_replace_callback_array

public function getContents()
{
    $subject = $this->articleContent->content;
    return  preg_replace_callback_array(
        [
            '/\bid\b\s*=\s*[\'\"]?([^\'\"]*)[\'\"]?/i' => function ($match) {
                $id = $match[0];
                $id = explode('=', $id)[1];
                $id = preg_replace('/\'/', '', $id);
                $data = ArticleImage::find()->where(['id'=>$id])->select('path')->scalar();
                return "src='{$data}'";
            },
        ],
        $subject
    );
}

3、sprintf

 //  获取13位时间戳
    private static function  getMillisecond(){
        list($t1, $t2) = explode(' ', microtime());
        return sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
    }

双子城
46 声望6 粉丝

just do it!