mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 23:28:14 +01:00
26 lines
616 B
PHP
26 lines
616 B
PHP
<?php
|
|
/**
|
|
* This function calculates
|
|
* Absolute min values from
|
|
* the different numbers
|
|
* provided.
|
|
*
|
|
* @param decimal $numbers A variable sized number input
|
|
* @return decimal $absoluteMin Absolute min value
|
|
*/
|
|
function absolute_min(...$numbers)
|
|
{
|
|
if (empty($numbers)) {
|
|
throw new \Exception('Please pass values to find absolute min value');
|
|
}
|
|
|
|
$absoluteMin = $numbers[0];
|
|
for ($loopIndex = 0; $loopIndex < count($numbers); $loopIndex++) {
|
|
if ($numbers[$loopIndex] < $absoluteMin) {
|
|
$absoluteMin = $numbers[$loopIndex];
|
|
}
|
|
}
|
|
|
|
return $absoluteMin;
|
|
}
|