Created
May 21, 2019 15:05
-
-
Save kevindees/1cb41e52a70c82ee5bbca1bdfae94d37 to your computer and use it in GitHub Desktop.
Helpers when using using empty()
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 | |
// do. if( empty_or($data['name'], $data['value']) ) | |
// vs. if( !empty($data['name']) || !empty($data['value']) ) | |
function empty_or(...$args) { | |
foreach ($args as $arg) { | |
if(empty($arg)) { return true; } | |
} | |
return false; | |
} | |
// do. if( empty_and($data['name'], $data['value']) ) | |
// vs. if( empty($data['name']) && empty($data['value']) ) | |
function empty_and(...$args) { | |
foreach ($args as $arg) { | |
if(!empty($arg)) { return false; } | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment