ArrayUtil::push_once()public staticWC 1.0

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

{} It's a method of the class: ArrayUtil{}

No Hooks.


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


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

Code of ArrayUtil::push_once() WC 7.1.0

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

	$array[] = $value;
	return true;