<?php
$numbers = [
'64 654 руб.',
'231 654 руб.',
'9 879 руб.',
'164 руб.',
'2 815 руб.'
];
var_dump(
getMinNumberFromArray($numbers, true), // float(164)
getMinNumberFromArray($numbers) // string(11) "164 руб.",
);
/**
* Поиск минимального числа в массиве
* @param array $numbers
* @param boolean $format
* @return string|flaot|null
*/
function getMinNumberFromArray(array $numbers, $format = false)
{
$minIndex = null;
$minNum = null;
foreach ($numbers as $k => $number) {
$number = (float)preg_replace("/[^0-9,.-]/", "", $number);
if (is_null($minNum) || $number < $minNum) {
$minIndex = $k;
$minNum = $number;
}
}
if(is_null($minNum)){
return null;
}
return ($format) ? $minNum : $numbers[$minIndex];
}