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

Duplicates any key not prefixed with ‘_’ creating a prefixed duplicate one.

The prefixing and duplication is recursive.


Parameters

$array

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

$recursive

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

Default value: false


Top ↑

Return

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


Top ↑

Source

File: src/Tribe/Utils/Array.php

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

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

				if ( 0 === strpos( $key, '_' ) ) {
					continue;
				}

				$prefixed[ '_' . $key ] = $value;
			}

			return array_merge( $array, $prefixed );
		}

Top ↑

Changelog

Changelog
Version Description
4.9.5 Introduced.