dozent_array_except( array $array, array|string $keys )

Get all of the given array except for a specified array of keys.


Parameters

$array

(array) (Required)

$keys

(array|string) (Required)


Return

(array)


Source

File: includes/core-functions.php

	function dozent_array_except( $array, $keys ) {
		//$array = (array) $array;
		//$array = array_filter( $array );

		$original = &$array;

		$keys = (array) $keys;

		if ( count( $keys ) === 0 ) {
			return;
		}

		foreach ( $keys as $key ) {
			// if the exact key exists in the top-level, remove it
			if ( array_key_exists( $key, $array ) ) {
				unset( $array[ $key ] );

				continue;
			}

			$parts = explode( '.', $key );

			// clean up before each pass
			$array = &$original;

			while ( count( $parts ) > 1 ) {
				$part = array_shift( $parts );

				if ( isset( $array[ $part ] ) && is_array( $array[ $part ] ) ) {
					$array = &$array[ $part ];
				} else {
					continue 2;
				}
			}

			unset( $array[ array_shift( $parts ) ] );
		}

		return $array;
	}


Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.