Last active
August 31, 2020 06:23
-
-
Save trvswgnr/1a39b5b9d6e3b77796f4e094bc15d7c9 to your computer and use it in GitHub Desktop.
PHP - parse args array with default
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 | |
function parse_args( $args, $defaults = '' ) { | |
if ( is_object( $args ) ) { | |
$r = get_object_vars( $args ); | |
} elseif ( is_array( $args ) ) { | |
$r =& $args; | |
} else { | |
parse_str( $args, $r ); | |
} | |
if ( is_array( $defaults ) ) { | |
return array_merge( $defaults, $r ); | |
} | |
return $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment