Which PHP Functions Should you Learn?

Most people know that PHP has a lot of functions but how many do you think there are? I spent a little while trying to work this out and after some judicious Googling, I came up with several answers.

  • In 2010, there were apparently 5,701 php functions.
  • If you run this code and echo out a count of the internal functions, you get 1,333.
  • This PHP function list page on the PHP.net website has approximately 10,919.

What’s the right answer and how many of them should you learn, if any? I still don’t really know 🙂

But, that brings me to a really interesting web page I came across at exakat.io which has performed some static analysis on a large number of open source PHP projects. They state that there are about 4,600 functions but that might just be a count of the used functions in their analysis, rather than existing functions. Anyway, the results are really intriguing.

If you visit that site, you can see the top 100 used functions based on frequency of use in other projects and how many times they are used, on average, within a project.

Rank Function Frequency Average
1 count 81.41 % 147.67
2 is_array 77.32 % 117.86
3 substr 74.62 % 142.92
4 in_array 74.16 % 79.55
5 explode 73.19 % 71.51
6 str_replace 72.32 % 101.05
7 implode 72.27 % 66.59
8 strlen 70.07 % 98.32
9 array_merge 69.46 % 64.01
10 strpos 67.98 % 78.18

The first (top) 10 from exakat.

Firstly, as they state, this is a great list for you to focus on when learning PHP. Many of those top 100 functions will end up being ones you will need to know, most likely. Moreover, against each is a link to the help page which makes that much easier to see what the function does.

Secondly, I noticed that md5 is used far too much. If you need to use hashing for passwords, despite md5’s apparent popularity, make sure you are using more secure methods, instead.

Lastly, one small thing I noticed was that chr is used the most within projects of the top 100, yet is number 87 on the list.

Rank Function Frequency Average
87 chr 35.34 % 186.97

Anyone know why? Hope you find that interesting, regardless.

 

twittergoogle_plusredditpinteresttumblrmail

Written by Stephen Moon
email: stephen at logicalmoon.com
www: https://www.logicalmoon.com


Hey! Did you enjoy reading this? If you did and would like an email when I add new content, just subscribe to my list. You can unsubscribe at any time.


This entry was posted in: php. Bookmark the ➜ permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *