php-ml/src/Math/Product.php

24 lines
405 B
PHP
Raw Normal View History

2016-04-20 22:23:03 +00:00
<?php
2016-04-25 20:55:34 +00:00
2016-11-20 21:53:17 +00:00
declare(strict_types=1);
2016-04-20 22:23:03 +00:00
namespace Phpml\Math;
class Product
{
/**
* @return mixed
*/
2016-04-21 20:12:45 +00:00
public static function scalar(array $a, array $b)
2016-04-20 22:23:03 +00:00
{
$product = 0;
foreach ($a as $index => $value) {
if (is_numeric($value) && is_numeric($b[$index])) {
$product += $value * $b[$index];
}
2016-04-20 22:23:03 +00:00
}
return $product;
}
}