Monday, 21 May 2018

The Definitive Guide To PHP's issetAnd empty

PHP has two very similar functions that are essential to writing good PHP applications, but whose purpose and exact function is rarely well explained: isset and empty. The PHP manual itself doesn't have a simple explanation that actually captures their essence and most posts written around the web seem to be missing some detail or other as well. This article attempts to fill that gap; and takes a broad sweep of related topics to do so. About PHP's Error Reporting To explain what these functions are needed for to begin with,...

Combining Array Functions Like a Boss

Combining Array Functions Like a Boss The real magic begins when you start to combine array functions. Here is how you can trim and remove empty values in just a single line of code with array_filter() and array_map(): 1 2 3 4 $values = ['say  ', '  bye', ' ', ' to', ' spaces ', '   '];   $words = array_filter(array_map('trim', $values)); print_r($words); // ['say', 'bye', 'to', 'spaces'] To create an id to a title map from an array of models, we can use a combination of array_combine() and array_column(): 1 2 3 4 5 6 $models...