- var_dump: documentation ( source)
- parse_str: documentation ( source)
- array_merge: documentation ( source)
- get_object_vars: documentation ( source)
<?php
/**
* Add the core functions.
*/
function apply_filters( $hook_name, $value ) {
return $value;
}
function wp_parse_str( $string, &$array ) {
parse_str( $string, $array );
/**
* Filters the array of variables derived from a parsed string.
*
* @since 2.3.0
*
* @param array $array The array populated with variables.
*/
$array = apply_filters( 'wp_parse_str', $array );
}
function wp_parse_args( $args, $defaults = array() ) {
if ( is_object( $args ) ) {
$parsed_args = get_object_vars( $args );
} elseif ( is_array( $args ) ) {
$parsed_args =& $args;
} else {
wp_parse_str( $args, $parsed_args );
}
if ( is_array( $defaults ) && $defaults ) {
return array_merge( $defaults, $parsed_args );
}
return $parsed_args;
}
/**
* Run the sample code to validate what happens when $args is null.
*/
$args = null;
$defaults = array( 'foo' => 'bar' );
$args = wp_parse_args( $args, $defaults );
var_dump( $args ); // array(1) { ["foo"]=> string(3) "bar" }