Skip to content

Instantly share code, notes, and snippets.

@RickvdStaaij
Last active Apr 15, 2016
Embed
What would you like to do?
Small and basic avoid else example
<?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