Field::get( string $key, mixed $default_val = null, array $arr = null )

Description #

Get a value from a path or default value if the path doesn’t exist

Parameters #

  • $key
    string (Required) Path.
  • $default_val
    mixed (Optional) Default value. Default value: null
  • $arr
    array (Optional) Array to search. Default value: null

Source #

File: lib/form/class-field.php

	public function get( $key, $default_val = null, $arr = null ) {
		$keys = explode( '.', (string) $key );

		if ( null === $arr ) {
			$arr = &$this->args;
		}

		foreach ( $keys as $key ) {
			if ( ! is_array( $arr ) || ! array_key_exists( $key, $arr ) ) {
				return $default_val;
			}

			$arr = &$arr[ $key ];
		}

		return $arr;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment