WordPress at a glance

wp_parse_args() WP 1.0

Merge user defined arguments into defaults array.

This function is used throughout WordPress to allow for both string or array to be merged into another array.

  • Since 2.3.0 $args can now also be an object.
Works based on: wp_parse_str()
✈ 1 time = 0.000018s = very fast | 50000 times = 0.08s = speed of light PHP 7.1.5, WP 4.8.2

No Hooks.

Return

Array. Merged user defined values with defaults.

Usage

wp_parse_args( $args, $defaults );
$args(string/array/object) (required)
Value to merge with $defaults.
$defaults(array)
Array that serves as the defaults.
Default: ''

Code of wp_parse_args: wp-includes/functions.php VER 4.9.8

<?php
function wp_parse_args( $args, $defaults = '' ) {
	if ( is_object( $args ) )
		$r = get_object_vars( $args );
	elseif ( is_array( $args ) )
		$r =& $args;
	else
		wp_parse_str( $args, $r );

	if ( is_array( $defaults ) )
		return array_merge( $defaults, $r );
	return $r;
}

Related Functions

From category: Helper Functions

No comments
    Hello, !     Log In . Register