dozent_array_get( null $key = null, array $array = array(), bool $default = false )

Return array value by given key, Get array key by dot notation


Description

Get any array value without any error, it will return you a null value if there is no key exists in the array that you wish to access It supports dot notation accessibility

Example usage:

dozent_array_get( 'key', $array );
dozent_array_get( 'key.child_dimension_key', $array );
dozent_array_get( 'key', $array, $default_value );

Note: you must pass an array in the second parameter.


Parameters

$key

(null) (Optional) Key item

Default value: null

$array

(array) (Optional) array

Default value: array()

$default

(bool) (Optional)

Default value: false


Return

(array|bool|mixed)


Source

File: includes/core-functions.php

	function dozent_array_get( $key = null, $array = [], $default = false ) {
		$array = (array) $array;
		if ( $key === null || ! count( $array ) ) {
			return $default;
		}
		$option_key_array = explode( '.', $key );

		$value = $array;

		foreach ( $option_key_array as $dotKey ) {
			if ( isset( $value[ $dotKey ] ) ) {
				$value = $value[ $dotKey ];
			} else {
				return $default;
			}
		}

		return $value;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.