Tribe__Utils__Array::add_unprefixed_keys_to( mixed $array, bool $recursive = false )

Duplicates any key prefixed with ‘_’ creating an un-prefixed duplicate one.

The un-prefixing and duplication is recursive.


Parameters

$array

(mixed) (Required) The array whose keys should be duplicated.

$recursive

(bool) (Optional) Whether the un-prefixing and duplication should be recursive or shallow.

Default value: false


Top ↑

Return

(array) The array with the duplicate, unprefixed, keys or the original input if not an array.


Top ↑

Source

File: src/Tribe/Utils/Array.php

		public static function add_unprefixed_keys_to( $array, $recursive = false ) {
			if ( ! is_array( $array ) ) {
				return $array;
			}

			$unprefixed = [];
			foreach ( $array as $key => $value ) {
				if ( $recursive && is_array( $value ) ) {
					$value = self::add_unprefixed_keys_to( $value, true );
					// And also add it to the original array.
					$array[ $key ] = array_merge( $array[ $key ], $value );
				}

				if ( 0 !== strpos( $key, '_' ) ) {
					continue;
				}
				$unprefixed[ substr( $key, 1 ) ] = $value;
			}

			return array_merge( $array, $unprefixed );
		}

Top ↑

Changelog

Changelog
Version Description
4.9.5 Introduced.