astra_get_prop( array $array, string $prop, string $default = null )

Get a specific property of an array without needing to check if that property exists.


Description

Provide a default value if you want to return a specific value if the property is not set.


Parameters

$array

(array) (Required) Array from which the property's value should be retrieved.

$prop

(string) (Required) Name of the property to be retrieved.

$default

(string) (Optional) Value that should be returned if the property is not set or empty. Defaults to null.

Default value: null


Return

(null|string|mixed) The value


Source

File: classes/helper-functions.php

	function astra_get_prop( $array, $prop, $default = null ) {

		if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) {
			return $default;
		}

		if ( ( isset( $array[ $prop ] ) && false === $array[ $prop ] ) ) {
			return false;
		}

		if ( isset( $array[ $prop ] ) ) {
			$value = $array[ $prop ];
		} else {
			$value = '';
		}

		return empty( $value ) && null !== $default ? $default : $value;
	}

Changelog

Changelog
Version Description
1.4.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.