收好100个最常用的PHP函数

  • 来源:网络
  • 更新日期:2020-07-07

摘要: 下面的列表是最常用的前100个 PHP 函数:它们是最常用的 PHP 中自带的函数。这些函数被命名使用,并从1到100进行

下面的列表是最常用的前100个 PHP 函数:它们是最常用的 PHP 中自带的函数。

这些函数被命名使用,并从1到100进行排序。 其他的4500个函数现在还没在排名中。 下面频率列表表示在 PHP 代码中使用此函数的频率 : 参考资料来自于 1900 个 PHP 开源项目。 他们使用了 Exakat static analysis engine 静态分析引擎的 1.2.5 版本进行了审核。平均值是在一个项目中调用此函数的次数。有些函数是被封装使用的,而另一些则是主要函数。

比如说,5个项目里面有4个用到了 count 函数,函数被调用大概150次。说明它很流行且被大量使用。

单击函数名跳转到 PHP 文档。在 Top 100文章的底部有一些总结见解。

排行函数频率平均值1count81.41 %147.672is_array77.32 %117.863substr74.62 %142.924in_array74.16 %79.555explode73.19 %71.516str_replace72.32 %101.057implode72.27 %66.598strlen70.07 %98.329array_merge69.46 %64.0110strpos67.98 %78.1811preg_match67.31 %76.6012sprintf67.16 %119.4613trim66.75 %81.2814strtolower65.99 %59.6215file_exists65.12 %45.1316is_string61.39 %45.1017preg_replace60.27 %54.2818file_get_contents59.96 %20.7119array_key_exists59.70 %57.5020array_keys59.35 %39.5921dirname56.44 %54.8422function_exists53.58 %42.6223array_map53.22 %19.4524get_class53.12 %33.0725class_exists52.50 %23.1326is_object51.94 %35.3527time51.79 %41.4228json_encode51.48 %24.8129date50.72 %52.1830is_null49.69 %60.5231is_numeric49.49 %40.6932array_shift49.49 %23.2833defined48.72 %86.8234is_dir48.57 %22.8635json_decode48.42 %17.3936header48.16 %59.7137strtoupper47.80 %30.9538array_values47.24 %17.2739md546.88 %23.7440method_exists46.73 %19.0541file_put_contents46.68 %12.4942rtrim45.91 %18.0843array_pop45.51 %20.6044unlink44.59 %23.5545basename44.59 %27.2346realpath44.08 %15.9047call_user_func43.97 %16.4148call_user_func_array43.92 %18.4049fopen43.77 %25.6150microtime43.46 %14.4151fclose42.85 %28.3652is_int42.75 %15.7853is_file42.08 %20.5254array_slice41.83 %13.2055preg_match_all40.55 %14.6656ucfirst40.25 %17.0257intval40.19 %88.1358str_repeat40.14 %19.5159serialize40.14 %22.0560array_filter39.99 %13.8761mkdir39.79 %11.1762is_callable39.43 %11.9463ltrim39.17 %10.9064ob_start39.12 %13.2665round39.07 %28.5666fwrite38.97 %23.3967array_unique38.87 %15.9668array_search38.82 %14.1969reset38.71 %20.7970array_unshift38.10 %10.3271parse_url37.90 %9.6172func_get_args37.79 %28.3373end37.49 %12.7074base64_encode37.39 %14.1575unserialize37.18 %18.3576max36.98 %22.8877preg_split36.98 %13.2778gettype36.93 %16.1679strrpos36.67 %11.9580version_compare36.67 %14.8781array_push36.67 %26.1882floor36.11 %18.7883strtotime36.01 %27.9484htmlspecialchars35.96 %51.0885ini_get35.85 %19.2586ini_set35.60 %14.4987chr35.34 %186.9788extension_loaded35.29 %14.1789is_bool35.24 %11.4490ksort34.98 %10.8291array_reverse34.93 %8.2792ord34.73 %53.1793uniqid34.68 %9.8394strtr34.47 %12.9095array_diff34.32 %11.1396error_reporting34.17 %8.9997ceil33.35 %11.9998urlencode33.30 %29.6399min32.69 %18.31100print_r32.64 %14.12前 100 分析

最常用的 PHP 函数是字符串函数,然后是数组函数,接着是文件函数。 (运算函数不在此列主要是因为他们通常基于运算符)

每个函数的链接都指向其对应的文档,事实上许多函数经过发展以及获得了许多新特性,例如:count() 的第二个参数,dirname() 的第二个参数以及 preg_match()str_replace() 接受数组作为参数等。有很多彩蛋。

以上 100 个函数没有近期要废弃的计划。

在非内置库中,mbstring 排名第一、curl 第二,然后是 gd、filter 和 iconv。

md5 是最常用的加密函数,其次是 Sha1 (#147)。

print_r 出现在 1/3 的项目代码里面的某处,任何地方 ...

由于 dirname(dirname(dirname())) 的调用,dirname 的使用频率非常高。

arrayechoprintemptyisset 这些没有纳入此排名,它们的使用度肯定是非常高的。

如下几个函数应该用运算符替代 : array_push, is_object, func_get_arg, chr, call_user_func

相当多的调用是为了知道值的类型。

数据库函数没有在这里排名:他们经常使用类,但功能仍然很频繁。可能是另一个前 100 名?

相比写入文件 PHP 更多的应用于读取文件。它还解码 base64。

使用键排序比使用值或使用键更频繁。

通常使用 file_get_contents 读取文件, 使用 fwrite 写入文件。

后记

如果你正在学习 PHP,最好回顾一下这里排名的 100 个功能。它们是你加入一个编码团队后最常找到的功能。它们不是唯一的,但遇到它们时你会不那么惊讶。

相关学习推荐:php编程从入门到精通