Created
August 16, 2013 18:14
-
-
Save staylor/6252177 to your computer and use it in GitHub Desktop.
PHP is ridic
This file contains hidden or 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 | |
/** | |
* | |
* @param array $set | |
* @param string $prop | |
* @return boolean | |
*/ | |
function _truthy_prop( $set, $prop ) { | |
if ( ! isset( $set[$prop] ) ) | |
return; | |
$non_empty_array = is_array( $set[$prop] ) && ! empty( $set[$prop] ); | |
if ( empty( $set[$prop] ) ) | |
$set[$prop] = false; | |
elseif ( '1' === $set[$prop] ) | |
$set[$prop] = true; | |
elseif ( 1 === $set[$prop] ) | |
$set[$prop] = true; | |
elseif ( 'false' === $set[$prop] ) | |
$set[$prop] = false; | |
elseif ( 'true' === $set[$prop] ) | |
$set[$prop] = true; | |
return $non_empty_array || $set[$prop]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment