BP_Group_Extension::parse_args_r( array $a, array $b )

Recursive argument parsing.


Description Description

This acts like a multi-dimensional version of wp_parse_args() (minus the querystring parsing – you must pass arrays).

Values from $a override those from $b; keys in $b that don’t exist in $a are passed through.

This is different from array_merge_recursive(), both because of the order of preference ($a overrides $b) and because of the fact that array_merge_recursive() combines arrays deep in the tree, rather than overwriting the b array with the a array.

The implementation of this function is specific to the needs of BP_Group_Extension, where we know that arrays will always be associative, and that an argument under a given key in one array will be matched by a value of identical depth in the other one. The function is NOT designed for general use, and will probably result in unexpected results when used with data in the wild. See, eg, https://core.trac.wordpress.org/ticket/19888


Parameters Parameters

$a

(Required) First set of arguments.

$b

(Required) Second set of arguments.


Top ↑

Return Return

(array) Parsed arguments.


Top ↑

Source Source

File: bp-groups/classes/class-bp-group-extension.php

	public static function parse_args_r( &$a, $b ) {
		$a = (array) $a;
		$b = (array) $b;
		$r = $b;

		foreach ( $a as $k => &$v ) {
			if ( is_array( $v ) && isset( $r[ $k ] ) ) {
				$r[ $k ] = self::parse_args_r( $v, $r[ $k ] );
			} else {
				$r[ $k ] = $v;
			}
		}

		return $r;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.