Tribe__Utils__Array::get( array $variable, array|string $indexes, mixed $default = null )

Find a value inside of an array or object, including one nested a few levels deep.

Example: get( $a, [ 0, 1, 2 ] ) returns the value of $a[0][1][2] or the default.


Parameters

$variable

(array) (Required) Array or object to search within.

$indexes

(array|string) (Required) Specify each nested index in order. Example: array( 'lvl1', 'lvl2' );

$default

(mixed) (Optional) Default value if the search finds nothing.

Default value: null


Top ↑

Return

(mixed) The value of the specified index or the default if not found.


Top ↑

Source

File: src/Tribe/Utils/Array.php

	public static function get( $variable, $indexes, $default = null ) {
		if ( is_object( $variable ) ) {
			$variable = (array) $variable;
		}

		if ( ! is_array( $variable ) ) {
			return $default;
		}

		foreach ( (array) $indexes as $index ) {
			if ( ! is_array( $variable ) || ! isset( $variable[ $index ] ) ) {
				$variable = $default;
				break;
			}

			$variable = $variable[ $index ];
		}

		return $variable;
	}