前 100 个 PHP 函数
以下列表展示了 100 个最常用的原生 PHP 函数。这些函数根据其在 PHP 代码存储库中的使用频率从 1 到 100 进行排名。参考语料库包括 2,500 个 PHP 开源项目列表(前 1,000 个 Composer 包、来自 GitHub/GitLab/Gitee 的公共存储库以及下载的档案)。分析是使用 Exakat 静态分析引擎版本 2.4.7 进行的。“平均”列表示函数在单个项目中被调用的频率。
例如,该count()函数在 5 个项目中的 4 个中使用,每个项目调用约 61 次。它既流行又被大量使用。另一方面,dirname()它虽然常用,但调用频率较低(56% 的项目使用了约 13 次)。
单击链接将直接转到每个函数的文档。列表末尾提供了其他见解。
100 个最流行的 PHP 函数:
| Rank | Function | Usage % | Count |
|---|---|---|---|
| 1 | file_exists | 66.05% | 18 |
| 2 | count | 63.67% | 87 |
| 3 | str_replace | 63.58% | 51 |
| 4 | implode | 62.72% | 48 |
| 5 | substr | 60.30% | 70 |
| 6 | array_merge | 60.02% | 51 |
| 7 | sprintf | 59.89% | 103 |
| 8 | dirname | 58.91% | 17 |
| 9 | explode | 58.30% | 37 |
| 10 | in_array | 58.27% | 49 |
| 11 | strpos | 58.08% | 31 |
| 12 | is_array | 58.05% | 73 |
| 13 | strlen | 56.37% | 45 |
| 14 | array_key_exists | 54.87% | 88 |
| 15 | array_keys | 54.72% | 23 |
| 16 | preg_match | 52.02% | 40 |
| 17 | file_get_contents | 51.76% | 11 |
| 18 | trim | 48.49% | 37 |
| 19 | is_string | 48.46% | 27 |
| 20 | array_values | 48.46% | 10 |
| 21 | is_file | 46.90% | 7 |
| 22 | method_exists | 46.62% | 11 |
| 23 | array_map | 46.11% | 17 |
| 24 | file_put_contents | 46.11% | 7 |
| 25 | strtolower | 45.44% | 26 |
| 26 | function_exists | 44.97% | 21 |
| 27 | preg_replace | 44.40% | 23 |
| 28 | defined | 43.44% | 27 |
| 29 | is_dir | 41.70% | 8 |
| 30 | json_decode | 41.54% | 10 |
| 31 | json_encode | 41.16% | 15 |
| 32 | call_user_func | 41.06% | 5 |
| 33 | array_filter | 41.00% | 10 |
| 34 | strtr | 40.55% | 6 |
| 35 | fwrite | 40.08% | 7 |
| 36 | rtrim | 39.85% | 8 |
| 37 | strrpos | 39.54% | 4 |
| 38 | call_user_func_array | 39.41% | 4 |
| 39 | filter_var | 39.25% | 3 |
| 40 | class_exists | 39.22% | 17 |
| 41 | header | 38.71% | 11 |
| 42 | array_flip | 38.62% | 3 |
| 43 | realpath | 38.11% | 6 |
| 44 | ini_get | 38.01% | 6 |
| 45 | get_class | 36.01% | 14 |
| 46 | is_object | 35.03% | 15 |
| 47 | unlink | 34.96% | 8 |
| 48 | trigger_error | 34.84% | 8 |
| 49 | array_shift | 34.71% | 8 |
| 50 | is_int | 33.76% | 7 |
| 51 | spl_autoload_register | 33.57% | 1 |
| 52 | is_numeric | 32.93% | 13 |
| 53 | strtoupper | 32.93% | 9 |
| 54 | mkdir | 32.93% | 4 |
| 55 | array_pop | 32.52% | 7 |
| 56 | ltrim | 31.95% | 5 |
| 57 | headers_sent | 31.95% | 2 |
| 58 | fopen | 31.88% | 8 |
| 59 | array_unique | 31.79% | 6 |
| 60 | str_repeat | 31.47% | 9 |
| 61 | basename | 31.25% | 6 |
| 62 | array_slice | 30.39% | 5 |
| 63 | fclose | 29.91% | 7 |
| 64 | time | 29.47% | 16 |
| 65 | is_callable | 29.37% | 5 |
| 66 | preg_match_all | 29.28% | 4 |
| 67 | is_bool | 29.15% | 3 |
| 68 | microtime | 28.74% | 5 |
| 69 | spl_autoload_unregister | 28.71% | 1 |
| 70 | var_export | 28.61% | 4 |
| 71 | array_unshift | 28.58% | 3 |
| 72 | max | 28.42% | 7 |
| 73 | array_search | 28.29% | 4 |
| 74 | apcu_fetch | 28.29% | 0 |
| 75 | extension_loaded | 28.20% | 4 |
| 76 | getcwd | 28.17% | 2 |
| 77 | preg_split | 28.14% | 4 |
| 78 | reset | 28.10% | 6 |
| 79 | end | 28.04% | 4 |
| 80 | gettype | 28.04% | 4 |
| 81 | stream_resolve_include_path | 27.85% | 0 |
| 82 | md5 | 27.72% | 6 |
| 83 | getenv | 27.66% | 6 |
| 84 | apcu_add | 27.41% | 0 |
| 85 | ucfirst | 27.34% | 7 |
| 86 | ksort | 27.31% | 3 |
| 87 | date | 27.18% | 14 |
| 88 | is_null | 26.90% | 27 |
| 89 | parse_url | 26.61% | 3 |
| 90 | preg_quote | 26.61% | 4 |
| 91 | array_reverse | 26.58% | 3 |
| 92 | array_diff | 26.45% | 4 |
| 93 | base64_encode | 26.14% | 4 |
| 94 | version_compare | 26.04% | 4 |
| 95 | preg_replace_callback | 25.91% | 4 |
| 96 | current | 25.25% | 3 |
| 97 | round | 25.25% | 7 |
| 98 | min | 25.15% | 4 |
| 99 | serialize | 25.02% | 6 |
从前 100 个 PHP 函数中获取见解
常见类别:最常用的函数与字符串、数组和文件处理有关。
数学函数:排名不突出,因为数学运算通常通过运算符来处理。
数据库功能:
pdo诸如、、mysqli*之类的功能pg_*大多通过类或组件来处理,因此不在列表中。弃用:前 100 名中没有出现最近弃用的功能。
Composer 的使用:由于流行的 Composer 包取代了某些本机功能,因此它们使用得较少。
加密函数:仅
md5()广泛出现;hash()排名第 159 位(此处未显示)。这需要改进,以实现更好的安全实践。调试功能:
print_r()类似或var_dump()不在前 100 名中的功能;但是,var_export()是否包含在内尚不明确。类型检查:
is_array()、is_string()和 等函数is_object()经常使用,突出了类型验证的重要性。运算符替换:
call_user_func()像和这样的函数call_user_func_array()可以被运算符替换,以获得更好的性能。

