Small and basic avoid else example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Using else example | |
*/ | |
function displayItems(array $items) | |
{ | |
if (count($array) > 0) { | |
foreach ($items as $item) { | |
addToDisplay($item); | |
} | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/** | |
* Avoided else exmaple | |
*/ | |
function displayItems(array $items) | |
{ | |
if (count($array) === 0) { | |
return false; | |
} | |
foreach ($items as $item) { | |
addToDisplay($item); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment