Posts

Showing posts from November, 2018

Advanced PHP: 7 useful techniques

In human languages, not all words are equally used, but they all have a purpose and unique power. The same is true for programming languages. A big part of the code we write is just variables, functions, classes, and loops. They are part of the basics you need to know to get your application done. Today I am not going to talk about them. Instead, I'll show you some of the PHP techniques I rarely use but have great impact.
Let's get started. Anonymous functions and classes Sometimes in your code, you must provide a callback function (in usort for example). Instead of defining a global function, you can create one dynamically, use it once or twice and remove it (if you want). It can also save you some time thinking about the right name (because naming things is important). In the following example an anonymous function is used as a callback to help sort people by age. $list = [ ['name' => 'John', 'age' => 31], ['name' => 'Mike…