WP_View_Config_Data::strip_nulls( mixed $value ): mixed

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

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

Description

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.

Parameters

$valuemixedrequired
The value to strip nulls from.

Return

mixed The value with every null property removed, recursively.

Source

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;
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

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