Automattic\WooCommerce\Utilities
ArrayUtil::push_once()
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( $items, $value ): bool;
- $items(array) (required)
- The array.
- $value(mixed) (required)
- The value to maybe push.
ArrayUtil::push_once() ArrayUtil::push once code WC 9.4.2
public static function push_once( array &$items, $value ): bool { if ( in_array( $value, $items, true ) ) { return false; } $items[] = $value; return true; }