Automattic\WooCommerce\Utilities

NumberUtil::array_sum()public staticWC 1.0

Get the sum of an array of values using the built-in array_sum function, but sanitize the array values first to ensure they are all floats.

This is needed because in PHP 8.3 non-numeric values that cannot be cast as an int or a float will cause an E_WARNING to be emitted. Prior to PHP 8.3 these values were just ignored.

Note that, unlike the built-in array_sum, this one will always return a float, never an int.

Метод класса: NumberUtil{}

Хуков нет.

Возвращает

float.

Использование

$result = NumberUtil::array_sum( $arr ): float;
$arr(массив) (обязательный)
The array of values to sum.

Код NumberUtil::array_sum() WC 9.8.2

public static function array_sum( array $arr ): float {
	$sanitized_array = array_map( 'floatval', $arr );

	return array_sum( $sanitized_array );
}