您的位置 首页 php

PHP中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.67
2is_array77.32 %117.86
3substr74.62 %142.92
4in_array74.16 %79.55
5explode73.19 %71.51
6str_replace72.32 %101.05
7implode72.27 %66.59
8strlen70.07 %98.32
9array_merge69.46 %64.01
10strpos67.98 %78.18
11preg_match67.31 %76.60
12sprintf67.16 %119.46
13trim66.75 %81.28
14strtolower65.99 %59.62
15file_exists65.12 %45.13
16is_string61.39 %45.10
17preg_replace60.27 %54.28
18file_get_contents59.96 %20.71
19array_key_exists59.70 %57.50
20array_keys59.35 %39.59
21dirname56.44 %54.84
22function_exists53.58 %42.62
23array_map53.22 %19.45
24get_class53.12 %33.07
25class_exists52.50 %23.13
26is_object51.94 %35.35
27time51.79 %41.42
28json_encode51.48 %24.81
29date50.72 %52.18
30is_null49.69 %60.52
31is_numeric49.49 %40.69
32array_shift49.49 %23.28
33defined48.72 %86.82
34is_dir48.57 %22.86
35json_decode48.42 %17.39
36header48.16 %59.71
37strtoupper47.80 %30.95
38array_values47.24 %17.27
39md546.88 %23.74
40method_exists46.73 %19.05
41file_put_contents46.68 %12.49
42rtrim45.91 %18.08
43array_pop45.51 %20.60
44unlink44.59 %23.55
45basename44.59 %27.23
46realpath44.08 %15.90
47call_user_func43.97 %16.41
48call_user_func_array43.92 %18.40
49fopen43.77 %25.61
50microtime43.46 %14.41
51fclose42.85 %28.36
52is_int42.75 %15.78
53is_file42.08 %20.52
54array_slice41.83 %13.20
55preg_match_all40.55 %14.66
56ucfirst40.25 %17.02
57intval40.19 %88.13
58str_repeat40.14 %19.51
59serialize40.14 %22.05
60array_filter39.99 %13.87
61mkdir39.79 %11.17
62is_callable39.43 %11.94
63ltrim39.17 %10.90
64ob_start39.12 %13.26
65round39.07 %28.56
66fwrite38.97 %23.39
67array_unique38.87 %15.96
68array_search38.82 %14.19
69reset38.71 %20.79
70array_unshift38.10 %10.32
71parse_url37.90 %9.61
72func_get_args37.79 %28.33
73end37.49 %12.70
74base64_encode37.39 %14.15
75unserialize37.18 %18.35
76max36.98 %22.88
77preg_split36.98 %13.27
78gettype36.93 %16.16
79strrpos36.67 %11.95
80version_compare36.67 %14.87
81array_push36.67 %26.18
82floor36.11 %18.78
83strtotime36.01 %27.94
84htmlspecialchars35.96 %51.08
85ini_get35.85 %19.25
86ini_set35.60 %14.49
87chr35.34 %186.97
88extension_loaded35.29 %14.17
89is_bool35.24 %11.44
90ksort34.98 %10.82
91array_reverse34.93 %8.27
92ord34.73 %53.17
93uniqid34.68 %9.83
94strtr34.47 %12.90
95array_diff34.32 %11.13
96error_reporting34.17 %8.99
97ceil33.35 %11.99
98urlencode33.30 %29.63
99min32.69 %18.31
100print_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 的使用频率非常高。

array、echo、print、empty、isset 这些没有纳入此排名,它们的使用度肯定是非常高的。

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

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

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

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

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

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

推荐教程:《PHP教程》

以上就是PHP中100个最常用的函数的详细内容,更多请关注求知技术网其它相关文章!

文章来源:智云一二三科技

文章标题:PHP中100个最常用的函数

文章地址:https://www.zhihuclub.com/1190.shtml

关于作者: 智云科技

热门文章

网站地图