WP_View_Config_Data::strip_nullsprivateWP 7.1.0

Recursively drops every property whose value is null from a value.

set() swaps a named key's value in wholesale rather than merging it into the current one, so it has no existing leaf for a nested null to delete the way merge() and replace() do. Stripping nulls here gives a nested null the same "drop the property it names" meaning under set() that it carries everywhere else. The same applies to a list replace() swaps in wholesale. A list is renumbered after a member is removed so removed entries do not leave gaps.

Method of the class: WP_View_Config_Data{}

No Hooks.

Returns

mixed. The value with every null property removed, recursively.

Usage

// private - for code of main (parent) class only
$result = $this->strip_nulls( $value );
$value(mixed) (required)
The value to strip nulls from.

Changelog

Since 7.1.0 Introduced.

WP_View_Config_Data::strip_nulls() code WP 7.1

private function strip_nulls( $value ) {
	if ( ! is_array( $value ) ) {
		return $value;
	}

	$result = array();
	foreach ( $value as $key => $item ) {
		// A null value drops the property it names.
		if ( null === $item ) {
			continue;
		}

		$result[ $key ] = $this->strip_nulls( $item );
	}

	// Renumber a list so a removed member does not leave a gap.
	return array_is_list( $value ) ? array_values( $result ) : $result;
}