Skip to content

Instantly share code, notes, and snippets.

@amaelftah
Created September 22, 2017 14:02
Show Gist options
  • Save amaelftah/bbe852636524d48b2c764d021f2b4105 to your computer and use it in GitHub Desktop.
Save amaelftah/bbe852636524d48b2c764d021f2b4105 to your computer and use it in GitHub Desktop.
in_array() instead of multiple or conditions
<?php
function isBlacklisted($name)
{
if ($name == 'ahmed' || $name == 'mohamed' || $name == 'ali' || $name == 'khaled' || $name == 'ayman')
{
return true;
}
return false;
}
//instead of multiple or conditions let's refactor it to use in_array method
function isBlacklisted($name)
{
$blacklistNames = ['ahmed','mohamed','ali','khaled','ayman'];
return in_array($name,$blacklistNames);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment