acf_update_nested_array()
acf_update_nested_array
This function will update a nested array value. Useful for modifying the $_POST array
No Hooks.
Returns
(true|false).
Usage
acf_update_nested_array( $array, $ancestors, $value );
- $array(required) (passed by reference — &)
- .
- $ancestors(required)
- .
- $value(required)
- .
Changelog
| Since 5.0.9 | Introduced. |
acf_update_nested_array() acf update nested array code ACF 6.8.8
function acf_update_nested_array( &$array, $ancestors, $value ) {
// if no more ancestors, update the current var
if ( empty( $ancestors ) ) {
$array = $value;
// return
return true;
}
// shift the next ancestor from the array
$k = array_shift( $ancestors );
// if exists
if ( isset( $array[ $k ] ) ) {
return acf_update_nested_array( $array[ $k ], $ancestors, $value );
}
// return
return false;
}