Automattic\WooCommerce\Utilities

ArrayUtil::push_once()public staticWC 1.0

Push a value to an array, but only if the value isn't in the array already.

Method of the class: ArrayUtil{}

No Hooks.

Return

true|false. True if the value has been added to the array, false if the value was already in the array.

Usage

$result = ArrayUtil::push_once( $array, $value ) : bool;
$array(array) (required)
The array.
$value(mixed) (required)
The value to maybe push.

ArrayUtil::push_once() code WC 8.7.0

public static function push_once( array &$array, $value ) : bool {
	if ( in_array( $value, $array, true ) ) {
		return false;
	}

	$array[] = $value;
	return true;
}