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
$valuemixed
The value to strip nulls from.
Return
mixed
The value with every null property removed, recursively.
Uses · 2
array_is_list()Polyfill for `array_is_list()` function added in PHP 8.1.
468privatefunctionstrip_nulls($value){469if(!is_array($value)){470return$value;471}472473$result=array();474foreach($valueas$key=>$item){475// A null value drops the property it names.476if(null===$item){477continue;478}479480$result[$key]=$this->strip_nulls($item);481}482483// Renumber a list so a removed member does not leave a gap.484returnarray_is_list($value)?array_values($result):$result;485}
History
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-view-config-data.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.