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) {
|
2016-07-26 06:14:57 +00:00
|
|
|
if (is_numeric($value) && is_numeric($b[$index])) {
|
2018-10-28 06:44:52 +00:00
|
|
|
$product += (float) $value * (float) $b[$index];
|
2016-07-26 06:14:57 +00:00
|
|
|
}
|
2016-04-20 22:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $product;
|
|
|
|
}
|
|
|
|
}
|