The 100 PHP functions that you have to know
There is a newer version of this top, in 2024.
Here is the top 100 PHP functions : it is the list of the most often used PHP native functions.
The functions are named, and ranked from 1 to 100. The other 4500 functions are not ranked here. The frequency column represents how often this function is used across PHP code repositories : the reference corpus is a list of 2500 PHP Open Source projects (top 1000 composer, github/gitlab/gitee public repo, downloaded archives…). They were audited with Exakat static analysis engine, version 2.4.7. The average is the number of time the function is called within one project.
For example, 4 project out of 5 uses the count() function, and when used, count() is called around 61 times. It is both a popular and heavily used function. On the other hand, dirname() is popular but rarely used (56% for 13 usages)
Click on the link to go to the documentation. Some insight at the bottom of the top 100.
The 100 most popular PHP functions
Rank | Function | Frequency | Average |
1 | file_exists | 62.80% | 13 |
2 | str_replace | 58.20% | 33 |
3 | implode | 57.31% | 35 |
4 | count | 56.42% | 61 |
5 | dirname | 56.38% | 13 |
6 | substr | 55.84% | 53 |
7 | sprintf | 55.26% | 80 |
8 | strpos | 55.07% | 24 |
9 | array_merge | 54.80% | 35 |
10 | in_array | 51.39% | 33 |
11 | explode | 51.35% | 26 |
12 | strlen | 50.97% | 35 |
13 | is_array | 50.73% | 46 |
14 | array_key_exists | 49.54% | 28 |
15 | array_keys | 49.27% | 16 |
16 | preg_match | 46.52% | 28 |
17 | file_get_contents | 46.48% | 8 |
18 | is_file | 44.43% | 6 |
19 | array_values | 42.81% | 7 |
20 | file_put_contents | 42.46% | 4 |
21 | trim | 41.57% | 25 |
22 | method_exists | 41.49% | 8 |
23 | defined | 40.87% | 19 |
24 | is_string | 40.76% | 20 |
25 | function_exists | 40.29% | 20 |
26 | array_map | 39.33% | 12 |
27 | preg_replace | 39.02% | 17 |
28 | strtolower | 38.94% | 19 |
29 | is_dir | 38.67% | 6 |
30 | strtr | 38.01% | 5 |
31 | call_user_func | 37.01% | 4 |
32 | strrpos | 36.70% | 4 |
33 | call_user_func_array | 36.43% | 3 |
34 | array_flip | 35.89% | 2 |
35 | fwrite | 35.89% | 4 |
36 | rtrim | 35.69% | 6 |
37 | filter_var | 35.65% | 2 |
38 | ini_get | 35.15% | 5 |
39 | json_decode | 34.76% | 7 |
40 | array_filter | 34.76% | 7 |
41 | realpath | 34.15% | 4 |
42 | header | 34.07% | 7 |
43 | class_exists | 34.03% | 12 |
44 | json_encode | 33.49% | 9 |
45 | trigger_error | 32.95% | 5 |
46 | get_class | 32.95% | 13 |
47 | spl_autoload_register | 32.10% | 1 |
48 | unlink | 30.43% | 5 |
49 | headers_sent | 29.78% | 1 |
50 | is_object | 29.31% | 11 |
51 | mkdir | 29.20% | 2 |
52 | array_shift | 28.69% | 6 |
53 | spl_autoload_unregister | 28.54% | 1 |
54 | apcu_fetch | 28.23% | 0 |
55 | array_pop | 28.11% | 5 |
56 | stream_resolve_include_path | 27.84% | 0 |
57 | is_int | 27.65% | 5 |
58 | apcu_add | 27.57% | 0 |
59 | getcwd | 27.49% | 1 |
60 | strtoupper | 27.42% | 6 |
61 | is_numeric | 26.95% | 9 |
62 | array_unique | 26.91% | 4 |
63 | ltrim | 26.60% | 4 |
64 | basename | 26.57% | 4 |
65 | str_repeat | 26.26% | 7 |
66 | fopen | 25.91% | 6 |
67 | array_slice | 24.94% | 3 |
68 | getenv | 24.94% | 4 |
69 | var_export | 24.71% | 3 |
70 | preg_match_all | 24.67% | 3 |
71 | is_callable | 24.48% | 4 |
72 | reset | 24.44% | 4 |
73 | preg_split | 24.40% | 3 |
74 | fclose | 24.36% | 5 |
75 | array_unshift | 24.25% | 3 |
76 | gettype | 24.21% | 4 |
77 | end | 23.90% | 3 |
78 | array_search | 23.82% | 3 |
79 | max | 23.78% | 5 |
80 | extension-loaded | 23.59% | 3 |
81 | is_bool | 23.55% | 2 |
82 | version_compare | 22.82% | 3 |
83 | preg_quote | 22.78% | 3 |
84 | time | 22.70% | 9 |
85 | ucfirst | 22.66% | 4 |
86 | ksort | 22.66% | 2 |
87 | preg_replace_callback | 22.54% | 3 |
88 | md5 | 22.51% | 4 |
89 | array_reverse | 22.47% | 2 |
90 | array_diff | 22.12% | 2 |
91 | is_readable | 22.00% | 1 |
92 | microtime | 21.96% | 4 |
93 | copy | 21.81% | 1 |
94 | parse_url | 21.81% | 2 |
95 | is_null | 21.50% | 17 |
96 | base64_encode | 21.42% | 3 |
97 | current | 21.38% | 2 |
98 | is_resource | 21.08% | 3 |
99 | serialize | 20.77% | 4 |
100 | key | 20.57% | 2 |
Top 100 insights
- The most commonly used PHP functions are string functions, and then arrays, then files.
- Math is probably out of the scope, as it is mostly based on operators
- Databases are probably out of scope, as they are based on classes
- No recently deprecated function is in the top 100.
- Usage of composer may also reduce the need for some native function, by federating them in a component or two, and reducing their overall usage. For example, monolog may both use log() and reduce its usage across the Open Source community.
- Extension that makes it to the top 100 : filter, json, apcu.
md5
is the only widely used crypto function.Sha1
is the second (#147).- Debug functions, such as print_r() or var_dump() are out of the top 100.
array
,echo
,print
,empty
,isset
and other language constructs were not counted as functions in this ranking. They are probably trusting the first ranks anyway.- Several functions should be replaced by operators :
array_push
,is_object
,func_get_arg
,chr
,call_user_func
. - Types are still a major concern of PHP code : is it a string? is it an object? No, it’s a resource!
- Type system may go a long way, but there are still return values that needs testing.
- There is also a PHP top 100 for the PHP classes. Wild ideas include top 100 PHP constants, operators, variable names,… Why not?
Challenges
If you are learning PHP, it is a good idea to review the 100 functions ranked here : they are the features you’ll find the most often when landing on a coding team. They are not the only ones, but you’ll be less surprised when meeting them.
More details?
Follow us on @exakat if you want more details, more stats