ap_parse_args( array $args, array $defaults = array() )

Description #

Merges user defined array arguments into the defaults array, which works with arrays only.

Parameters #

  • $args
    array (Required) Value to be merged with the defaults array.
  • $defaults
    array (Optional) Array that serves as the defaults. Default value: array()

Changelog #

VersionDescription
4.4.0Introduced.

Source #

File: includes/functions.php

function ap_parse_args( array $args, $defaults = array() ) {
	$new_args = $defaults;

	foreach ( $args as $key => $value ) {
		if ( is_array( $value ) && isset( $new_args[ $key ] ) ) {
			$new_args[ $key ] = ap_parse_args( $value, $new_args[ $key ] );
		} else {
			$new_args[ $key ] = $value;
		}
	}

	return $new_args;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment