---
title: "Top 100 PHP functions"
url: https://www.exakat.io/top-100-php-functions/
date: 2018-05-31
modified: 2023-12-03
author: "dams"
description: "[caption id=\"attachment_4255\" align=\"alignleft\" width=\"300\"] The top 100 PHP functions[/caption] The 100 PHP functions that you have to know There is a newer top PHP functions in 2022 here!.  Here is..."
categories:
  - "Technology"
tags:
  - "documentation"
  - "functions"
  - "php"
  - "top 100"
image: https://www.exakat.io/wp-content/uploads/2018/05/keys.320.jpg
word_count: 968
---

# Top 100 PHP functions

[![top 100 PHP functions](https://178.62.231.40/wp-content/uploads/2018/05/keys.320-300x300.jpg)](https://178.62.231.40/wp-content/uploads/2018/05/keys.320.jpg)The top 100 PHP functions

# The 100 PHP functions that you have to know

## There is a newer top PHP functions in 2022 here!. 

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 now. The frequency column represents how often this function is used across PHP code : the reference corpus is a list of 1900 PHP open source projects. They were audited with [Exakat static analysis engine](https://www.exakat.io/), version 1.2.5. The average is the number of time a function is called within one project. Some function are used in isolation, and others are a staple.

For example, 4 project out of 5 uses the count function, and when used, the function is called around 150 times. It is both a popular and heavily used function.

Click on the link to go to the documentation. Some insight at the bottom of the top 100.

| **Rank** | **Function** | **Frequency** | **Average** |
| -------- | ------------ | ------------- | ----------- |
| 1 | [count](http://php.net/count) | 81.41 % | 147.67 |
| 2 | [is_array](http://php.net/is_array) | 77.32 % | 117.86 |
| 3 | [substr](http://php.net/substr) | 74.62 % | 142.92 |
| 4 | [in_array](http://php.net/in_array) | 74.16 % | 79.55 |
| 5 | [explode](http://php.net/explode) | 73.19 % | 71.51 |
| 6 | [str_replace](http://php.net/str_replace) | 72.32 % | 101.05 |
| 7 | [implode](http://php.net/implode) | 72.27 % | 66.59 |
| 8 | [strlen](http://php.net/strlen) | 70.07 % | 98.32 |
| 9 | [array_merge](http://php.net/array_merge) | 69.46 % | 64.01 |
| 10 | [strpos](http://php.net/strpos) | 67.98 % | 78.18 |
| 11 | [preg_match](http://php.net/preg_match) | 67.31 % | 76.60 |
| 12 | [sprintf](http://php.net/sprintf) | 67.16 % | 119.46 |
| 13 | [trim](http://php.net/trim) | 66.75 % | 81.28 |
| 14 | [strtolower](http://php.net/strtolower) | 65.99 % | 59.62 |
| 15 | [file_exists](http://php.net/file_exists) | 65.12 % | 45.13 |
| 16 | [is_string](http://php.net/is_string) | 61.39 % | 45.10 |
| 17 | [preg_replace](http://php.net/preg_replace) | 60.27 % | 54.28 |
| 18 | [file_get_contents](http://php.net/file_get_contents) | 59.96 % | 20.71 |
| 19 | [array_key_exists](http://php.net/array_key_exists) | 59.70 % | 57.50 |
| 20 | [array_keys](http://php.net/array_keys) | 59.35 % | 39.59 |
| 21 | [dirname](http://php.net/dirname) | 56.44 % | 54.84 |
| 22 | [function_exists](http://php.net/function_exists) | 53.58 % | 42.62 |
| 23 | [array_map](http://php.net/array_map) | 53.22 % | 19.45 |
| 24 | [get_class](http://php.net/get_class) | 53.12 % | 33.07 |
| 25 | [class_exists](http://php.net/class_exists) | 52.50 % | 23.13 |
| 26 | [is_object](http://php.net/is_object) | 51.94 % | 35.35 |
| 27 | [time](http://php.net/time) | 51.79 % | 41.42 |
| 28 | [json_encode](http://php.net/json_encode) | 51.48 % | 24.81 |
| 29 | [date](http://php.net/date) | 50.72 % | 52.18 |
| 30 | [is_null](http://php.net/is_null) | 49.69 % | 60.52 |
| 31 | [is_numeric](http://php.net/is_numeric) | 49.49 % | 40.69 |
| 32 | [array_shift](http://php.net/array_shift) | 49.49 % | 23.28 |
| 33 | [defined](http://php.net/defined) | 48.72 % | 86.82 |
| 34 | [is_dir](http://php.net/is_dir) | 48.57 % | 22.86 |
| 35 | [json_decode](http://php.net/json_decode) | 48.42 % | 17.39 |
| 36 | [header](http://php.net/header) | 48.16 % | 59.71 |
| 37 | [strtoupper](http://php.net/strtoupper) | 47.80 % | 30.95 |
| 38 | [array_values](http://php.net/array_values) | 47.24 % | 17.27 |
| 39 | [md5](http://php.net/md5) | 46.88 % | 23.74 |
| 40 | [method_exists](http://php.net/method_exists) | 46.73 % | 19.05 |
| 41 | [file_put_contents](http://php.net/file_put_contents) | 46.68 % | 12.49 |
| 42 | [rtrim](http://php.net/rtrim) | 45.91 % | 18.08 |
| 43 | [array_pop](http://php.net/array_pop) | 45.51 % | 20.60 |
| 44 | [unlink](http://php.net/unlink) | 44.59 % | 23.55 |
| 45 | [basename](http://php.net/basename) | 44.59 % | 27.23 |
| 46 | [realpath](http://php.net/realpath) | 44.08 % | 15.90 |
| 47 | [call_user_func](http://php.net/call_user_func) | 43.97 % | 16.41 |
| 48 | [call_user_func_array](http://php.net/call_user_func_array) | 43.92 % | 18.40 |
| 49 | [fopen](http://php.net/fopen) | 43.77 % | 25.61 |
| 50 | [microtime](http://php.net/microtime) | 43.46 % | 14.41 |
| 51 | [fclose](http://php.net/fclose) | 42.85 % | 28.36 |
| 52 | [is_int](http://php.net/is_int) | 42.75 % | 15.78 |
| 53 | [is_file](http://php.net/is_file) | 42.08 % | 20.52 |
| 54 | [array_slice](http://php.net/array_slice) | 41.83 % | 13.20 |
| 55 | [preg_match_all](http://php.net/preg_match_all) | 40.55 % | 14.66 |
| 56 | [ucfirst](http://php.net/ucfirst) | 40.25 % | 17.02 |
| 57 | [intval](http://php.net/intval) | 40.19 % | 88.13 |
| 58 | [str_repeat](http://php.net/str_repeat) | 40.14 % | 19.51 |
| 59 | [serialize](http://php.net/serialize) | 40.14 % | 22.05 |
| 60 | [array_filter](http://php.net/array_filter) | 39.99 % | 13.87 |
| 61 | [mkdir](http://php.net/mkdir) | 39.79 % | 11.17 |
| 62 | [is_callable](http://php.net/is_callable) | 39.43 % | 11.94 |
| 63 | [ltrim](http://php.net/ltrim) | 39.17 % | 10.90 |
| 64 | [ob_start](http://php.net/ob_start) | 39.12 % | 13.26 |
| 65 | [round](http://php.net/round) | 39.07 % | 28.56 |
| 66 | [fwrite](http://php.net/fwrite) | 38.97 % | 23.39 |
| 67 | [array_unique](http://php.net/array_unique) | 38.87 % | 15.96 |
| 68 | [array_search](http://php.net/array_search) | 38.82 % | 14.19 |
| 69 | [reset](http://php.net/reset) | 38.71 % | 20.79 |
| 70 | [array_unshift](http://php.net/array_unshift) | 38.10 % | 10.32 |
| 71 | [parse_url](http://php.net/parse_url) | 37.90 % | 9.61 |
| 72 | [func_get_args](http://php.net/func_get_args) | 37.79 % | 28.33 |
| 73 | [end](http://php.net/end) | 37.49 % | 12.70 |
| 74 | [base64_encode](http://php.net/base64_encode) | 37.39 % | 14.15 |
| 75 | [unserialize](http://php.net/unserialize) | 37.18 % | 18.35 |
| 76 | [max](http://php.net/max) | 36.98 % | 22.88 |
| 77 | [preg_split](http://php.net/preg_split) | 36.98 % | 13.27 |
| 78 | [gettype](http://php.net/gettype) | 36.93 % | 16.16 |
| 79 | [strrpos](http://php.net/strrpos) | 36.67 % | 11.95 |
| 80 | [version_compare](http://php.net/version_compare) | 36.67 % | 14.87 |
| 81 | [array_push](http://php.net/array_push) | 36.67 % | 26.18 |
| 82 | [floor](http://php.net/floor) | 36.11 % | 18.78 |
| 83 | [strtotime](http://php.net/strtotime) | 36.01 % | 27.94 |
| 84 | [htmlspecialchars](http://php.net/htmlspecialchars) | 35.96 % | 51.08 |
| 85 | [ini_get](http://php.net/ini_get) | 35.85 % | 19.25 |
| 86 | [ini_set](http://php.net/ini_set) | 35.60 % | 14.49 |
| 87 | [chr](http://php.net/chr) | 35.34 % | 186.97 |
| 88 | [extension_loaded](http://php.net/extension_loaded) | 35.29 % | 14.17 |
| 89 | [is_bool](http://php.net/is_bool) | 35.24 % | 11.44 |
| 90 | [ksort](http://php.net/ksort) | 34.98 % | 10.82 |
| 91 | [array_reverse](http://php.net/array_reverse) | 34.93 % | 8.27 |
| 92 | [ord](http://php.net/ord) | 34.73 % | 53.17 |
| 93 | [uniqid](http://php.net/uniqid) | 34.68 % | 9.83 |
| 94 | [strtr](http://php.net/strtr) | 34.47 % | 12.90 |
| 95 | [array_diff](http://php.net/array_diff) | 34.32 % | 11.13 |
| 96 | [error_reporting](http://php.net/error_reporting) | 34.17 % | 8.99 |
| 97 | [ceil](http://php.net/ceil) | 33.35 % | 11.99 |
| 98 | [urlencode](http://php.net/urlencode) | 33.30 % | 29.63 |
| 99 | [min](http://php.net/min) | 32.69 % | 18.31 |
| 100 | [print_r](http://php.net/print_r) | 32.64 % | 14.12 |

## 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)
- The links leads to the documentation : many of those functions actually evolved and acquired new features : for example, `count()`'s second argument, `dirname()`'s second argument, `preg_match()` and `str_replace()` accepting arrays as argument... There are many easter eggs.
- No recently deprecated function is in the top 100.
- ext/mbstring is the first non-core extension to show up; ext/curl is the second; then Gd, filter and iconv.
- `md5` is the only widely used crypto function. `Sha1` is the second (#147).
- `print_r` is used somewhere in the code of 1 project out of 3. Somewhere...
- `dirname` has a high level of usage, due to `dirname(dirname(dirname()))` calls
- `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`.
- Quite a lot of calls are devoted to knowing a value's type
- Databases are not ranked here : they are often using classes, though functions are still frequent. May be another top 100 ?
- PHP code tends to read files more than write them. It also decodes base64
- sorting with keys is more frequent than on values or with keys.
- files are read with `file_get_contents`, and written with `fwrite`

## 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.