Some Tips For PHP developers

Tips for PHP developers to write shorter and high-performance code


A slick way to return a Boolean

return $age >= 15 && $age <= 24;

Be careful when using strpos

// This if condition not work because strpos() returns 0 and 0 is false
if (strpos('Foo Bar Baz', 'F')) {
echo 'Found';
// This will work properly.
if (strpos('Foo Bar Baz', 'F') !== false) {
echo 'Found';

Count() function in php 7.2

$count = [];
if(is_array($count) || $count instanceof Countable) {
echo count($count);

Backend Developer, Flexitarian, Technology enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store