acf_extract_var()ACF 5.0.0

This function will remove the var from the array, and return the var

No Hooks.

Returns

Mixed. Extracted var or default.

Usage

acf_extract_var( $extract_array, $key, $default_value );
$extract_array(array) (required) (passed by reference — &)
an array passed as reference to be extracted.
$key(string) (required)
The key to extract from the array.
$default_value(mixed)
The default value if it doesn't exist in the extract array.
Default: null

Changelog

Since 5.0.0 Introduced.

acf_extract_var() code ACF 6.8.8

function acf_extract_var( &$extract_array, $key, $default_value = null ) {
	// check if exists - uses array_key_exists to extract NULL values (isset will fail).
	if ( is_array( $extract_array ) && array_key_exists( $key, $extract_array ) ) {

		// store and unset value.
		$v = $extract_array[ $key ];
		unset( $extract_array[ $key ] );

		return $v;
	}

	return $default_value;
}