---
title: "The 100 PHP functions in 2022"
url: https://www.exakat.io/the-100-php-functions-in-2022/
date: 2022-07-27
modified: 2024-12-16
author: "dams"
description: "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..."
categories:
  - "Code auditing"
tags:
  - "functions"
  - "php"
  - "ranking"
  - "top"
image: https://www.exakat.io/wp-content/uploads/2018/05/keys.320.jpg
word_count: 879
---

# The 100 PHP functions in 2022

# 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](https://www.exakat.io/), 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()](https://php.net/count) function, and when used, [count()](https://php.net/count) is called around 61 times. It is both a popular and heavily used function. On the other hand, [dirname()](http://php.net/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](https://www.php.net/manual/en/function.file-exists.php) | 62.80% | 13 |
| 2 | [str_replace](https://www.php.net/manual/en/function.str-replace.php) | 58.20% | 33 |
| 3 | [implode](https://www.php.net/manual/en/function.implode.php) | 57.31% | 35 |
| 4 | [count](https://www.php.net/manual/en/function.count.php) | 56.42% | 61 |
| 5 | [dirname](https://www.php.net/manual/en/function.dirname.php) | 56.38% | 13 |
| 6 | [substr](https://www.php.net/manual/en/function.substr.php) | 55.84% | 53 |
| 7 | [sprintf](https://www.php.net/manual/en/function.sprintf.php) | 55.26% | 80 |
| 8 | [strpos](https://www.php.net/manual/en/function.strpos.php) | 55.07% | 24 |
| 9 | [array_merge](https://www.php.net/manual/en/function.array-merge.php) | 54.80% | 35 |
| 10 | [in_array](https://www.php.net/manual/en/function.in-array.php) | 51.39% | 33 |
| 11 | [explode](https://www.php.net/manual/en/function.explode.php) | 51.35% | 26 |
| 12 | [strlen](https://www.php.net/manual/en/function.strlen.php) | 50.97% | 35 |
| 13 | [is_array](https://www.php.net/manual/en/function.is-array.php) | 50.73% | 46 |
| 14 | [array_key_exists](https://www.php.net/manual/en/function.array-key-exists.php) | 49.54% | 28 |
| 15 | [array_keys](https://www.php.net/manual/en/function.array-keys.php) | 49.27% | 16 |
| 16 | [preg_match](https://www.php.net/manual/en/function.preg-match.php) | 46.52% | 28 |
| 17 | [file_get_contents](https://www.php.net/manual/en/function.file-get-contents.php) | 46.48% | 8 |
| 18 | [is_file](https://www.php.net/manual/en/function.is-file.php) | 44.43% | 6 |
| 19 | [array_values](https://www.php.net/manual/en/function.array-values.php) | 42.81% | 7 |
| 20 | [file_put_contents](https://www.php.net/manual/en/function.file-put-contents.php) | 42.46% | 4 |
| 21 | [trim](https://www.php.net/manual/en/function.trim.php) | 41.57% | 25 |
| 22 | [method_exists](https://www.php.net/manual/en/function.method-exists.php) | 41.49% | 8 |
| 23 | [defined](https://www.php.net/manual/en/function.defined.php) | 40.87% | 19 |
| 24 | [is_string](https://www.php.net/manual/en/function.is-string.php) | 40.76% | 20 |
| 25 | [function_exists](https://www.php.net/manual/en/function.function-exists.php) | 40.29% | 20 |
| 26 | [array_map](https://www.php.net/manual/en/function.array-map.php) | 39.33% | 12 |
| 27 | [preg_replace](https://www.php.net/manual/en/function.preg-replace.php) | 39.02% | 17 |
| 28 | [strtolower](https://www.php.net/manual/en/function.strtolower.php) | 38.94% | 19 |
| 29 | [is_dir](https://www.php.net/manual/en/function.is-dir.php) | 38.67% | 6 |
| 30 | [strtr](https://www.php.net/manual/en/function.strtr.php) | 38.01% | 5 |
| 31 | [call_user_func](https://www.php.net/manual/en/function.call-user-func.php) | 37.01% | 4 |
| 32 | [strrpos](https://www.php.net/manual/en/function.strrpos.php) | 36.70% | 4 |
| 33 | [call_user_func_array](https://www.php.net/manual/en/function.call-user-func-array.php) | 36.43% | 3 |
| 34 | [array_flip](https://www.php.net/manual/en/function.array-flip.php) | 35.89% | 2 |
| 35 | [fwrite](https://www.php.net/manual/en/function.fwrite.php) | 35.89% | 4 |
| 36 | [rtrim](https://www.php.net/manual/en/function.rtrim.php) | 35.69% | 6 |
| 37 | [filter_var](https://www.php.net/manual/en/function.filter-var.php) | 35.65% | 2 |
| 38 | [ini_get](https://www.php.net/manual/en/function.ini-get.php) | 35.15% | 5 |
| 39 | [json_decode](https://www.php.net/manual/en/function.json-decode.php) | 34.76% | 7 |
| 40 | [array_filter](https://www.php.net/manual/en/function.array-filter.php) | 34.76% | 7 |
| 41 | [realpath](https://www.php.net/manual/en/function.realpath.php) | 34.15% | 4 |
| 42 | [header](https://www.php.net/manual/en/function.header.php) | 34.07% | 7 |
| 43 | [class_exists](https://www.php.net/manual/en/function.class-exists.php) | 34.03% | 12 |
| 44 | [json_encode](https://www.php.net/manual/en/function.json-encode.php) | 33.49% | 9 |
| 45 | [trigger_error](https://www.php.net/manual/en/function.trigger-error.php) | 32.95% | 5 |
| 46 | [get_class](https://www.php.net/manual/en/function.get-class.php) | 32.95% | 13 |
| 47 | [spl_autoload_register](https://www.php.net/manual/en/function.spl-autoload-register.php) | 32.10% | 1 |
| 48 | [unlink](https://www.php.net/manual/en/function.unlink.php) | 30.43% | 5 |
| 49 | [headers_sent](https://www.php.net/manual/en/function.headers-sent.php) | 29.78% | 1 |
| 50 | [is_object](https://www.php.net/manual/en/function.is-object.php) | 29.31% | 11 |
| 51 | [mkdir](https://www.php.net/manual/en/function.mkdir.php) | 29.20% | 2 |
| 52 | [array_shift](https://www.php.net/manual/en/function.array-shift.php) | 28.69% | 6 |
| 53 | [spl_autoload_unregister](https://www.php.net/manual/en/function.spl-autoload-unregister.php) | 28.54% | 1 |
| 54 | [apcu_fetch](https://www.php.net/manual/en/function.apcu-fetch.php) | 28.23% | 0 |
| 55 | [array_pop](https://www.php.net/manual/en/function.array-pop.php) | 28.11% | 5 |
| 56 | [stream_resolve_include_path](https://www.php.net/manual/en/function.stream-resolve-include-path.php) | 27.84% | 0 |
| 57 | [is_int](https://www.php.net/manual/en/function.is-int.php) | 27.65% | 5 |
| 58 | [apcu_add](https://www.php.net/manual/en/function.apcu-add.php) | 27.57% | 0 |
| 59 | [getcwd](https://www.php.net/manual/en/function.getcwd.php) | 27.49% | 1 |
| 60 | [strtoupper](https://www.php.net/manual/en/function.strtoupper.php) | 27.42% | 6 |
| 61 | [is_numeric](https://www.php.net/manual/en/function.is-numeric.php) | 26.95% | 9 |
| 62 | [array_unique](https://www.php.net/manual/en/function.array-unique.php) | 26.91% | 4 |
| 63 | [ltrim](https://www.php.net/manual/en/function.ltrim.php) | 26.60% | 4 |
| 64 | [basename](https://www.php.net/manual/en/function.basename.php) | 26.57% | 4 |
| 65 | [str_repeat](https://www.php.net/manual/en/function.str-repeat.php) | 26.26% | 7 |
| 66 | [fopen](https://www.php.net/manual/en/function.fopen.php) | 25.91% | 6 |
| 67 | [array_slice](https://www.php.net/manual/en/function.array-slice.php) | 24.94% | 3 |
| 68 | [getenv](https://www.php.net/manual/en/function.getenv.php) | 24.94% | 4 |
| 69 | [var_export](https://www.php.net/manual/en/function.var-export.php) | 24.71% | 3 |
| 70 | [preg_match_all](https://www.php.net/manual/en/function.preg-match-all.php) | 24.67% | 3 |
| 71 | [is_callable](https://www.php.net/manual/en/function.is-callable.php) | 24.48% | 4 |
| 72 | [reset](https://www.php.net/manual/en/function.reset.php) | 24.44% | 4 |
| 73 | [preg_split](https://www.php.net/manual/en/function.preg-split.php) | 24.40% | 3 |
| 74 | [fclose](https://www.php.net/manual/en/function.fclose.php) | 24.36% | 5 |
| 75 | [array_unshift](https://www.php.net/manual/en/function.array-unshift.php) | 24.25% | 3 |
| 76 | [gettype](https://www.php.net/manual/en/function.gettype.php) | 24.21% | 4 |
| 77 | [end](https://www.php.net/manual/en/function.end.php) | 23.90% | 3 |
| 78 | [array_search](https://www.php.net/manual/en/function.array-search.php) | 23.82% | 3 |
| 79 | [max](https://www.php.net/manual/en/function.max.php) | 23.78% | 5 |
| 80 | [extension-loaded](https://www.php.net/manual/en/function.extension-loaded.php) | 23.59% | 3 |
| 81 | [is_bool](https://www.php.net/manual/en/function.is-bool.php) | 23.55% | 2 |
| 82 | [version_compare](https://www.php.net/manual/en/function.version-compare.php) | 22.82% | 3 |
| 83 | [preg_quote](https://www.php.net/manual/en/function.preg-quote.php) | 22.78% | 3 |
| 84 | [time](https://www.php.net/manual/en/function.time.php) | 22.70% | 9 |
| 85 | [ucfirst](https://www.php.net/manual/en/function.ucfirst.php) | 22.66% | 4 |
| 86 | [ksort](https://www.php.net/manual/en/function.ksort.php) | 22.66% | 2 |
| 87 | [preg_replace_callback](https://www.php.net/manual/en/function.preg-replace-callback.php) | 22.54% | 3 |
| 88 | [md5](https://www.php.net/manual/en/function.md5.php) | 22.51% | 4 |
| 89 | [array_reverse](https://www.php.net/manual/en/function.array-reverse.php) | 22.47% | 2 |
| 90 | [array_diff](https://www.php.net/manual/en/function.array-diff.php) | 22.12% | 2 |
| 91 | [is_readable](https://www.php.net/manual/en/function.is-readable.php) | 22.00% | 1 |
| 92 | [microtime](https://www.php.net/manual/en/function.microtime.php) | 21.96% | 4 |
| 93 | [copy](https://www.php.net/manual/en/function.copy.php) | 21.81% | 1 |
| 94 | [parse_url](https://www.php.net/manual/en/function.parse-url.php) | 21.81% | 2 |
| 95 | [is_null](https://www.php.net/manual/en/function.is-null.php) | 21.50% | 17 |
| 96 | [base64_encode](https://www.php.net/manual/en/function.base64-encode.php) | 21.42% | 3 |
| 97 | [current](https://www.php.net/manual/en/function.current.php) | 21.38% | 2 |
| 98 | [is_resource](https://www.php.net/manual/en/function.is-resource.php) | 21.08% | 3 |
| 99 | [serialize](https://www.php.net/manual/en/function.serialize.php) | 20.77% | 4 |
| 100 | [key](https://www.php.net/manual/en/function.key.php) | 20.57% | 2 |

## Top 100 insights

- The most commonly used PHP functions are [string](https://www.php.net/manual/en/language.types.string.php) functions, and then [arrays](https://www.php.net/manual/en/language.types.array.php), then [files](https://www.php.net/manual/en/ref.filesystem.php).

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](https://getcomposer.org/) 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](https://github.com/Seldaek/monolog) may both use [log](https://php.net/log)() and reduce its usage across the Open Source community.
- Extension that makes it to the top 100 : [filter](https://www.php.net/manual/en/book.filter.php), [json](https://www.php.net/manual/json/book.filter.php), [apcu](https://www.php.net/manual/apcu/book.filter.php).
- `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](https://www.exakat.io/en/top-100-php-classes-that-you-should-know/). 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](https://twitter.com/exakat) if you want more details, more stats