$string = '40|https://site1.com/files/02bea218b601ef2cbc74e08dc8d78_1000_1000.png;77|https://site1.com/files/29037cbdc27707fe2d6b2cf4d3924_1000_1000.png;78|https://site1.com/files/923b6f214f8bffcf20fbbebe5365b_1000_1000.png;85|https://site1.com/files/f8b6dbe261e89877e23e6a6f00003_1000_1000.png';
$result = rtrim(preg_replace('~\|[^;]+(?:;|$)~', ',', $string), ',');
echo $result; // 40,77,78,85
function formatNumber(int $int): String
{
$k = (int) log($int, 1000);
$float = round($int / pow(1000, $k), 1);
$letters = ['К', 'М', 'Млрд'];
return $float . ($letters[--$k] ?? '');
}
// Примеры использования:
echo formatNumber(7); // 7
echo formatNumber(78); // 78
echo formatNumber(789); // 789
echo formatNumber(7899); // 7.9К
echo formatNumber(78991); // 79К
echo formatNumber(789919); // 789.9К
echo formatNumber(7899191); // 7.9М
echo formatNumber(78991911); // 79М
echo formatNumber(789919119); // 789.9М
echo formatNumber(7899191191); // 7.9Млрд
echo formatNumber(78991911910); // 79Млрд
$str = '345.45';
$int = (int) str_replace('.', '', $str);
var_dump($int); // int(34545)
$float = preg_replace('~\d+\K(\d{2})$~', '.$1', $int);
$float = (float) number_format(($float * 0.15), 1, '.', '');
var_dump($float); // float(51.8)
$styles = [
'grid-2h',
'grid-2h',
'grid-1',
'grid-1',
'grid-4',
'grid-4'
];
shuffle($styles);
$total = count($styles);
$trigger = 1;
$buffer = [];
while ($trigger) {
foreach ($styles as $k => $style) {
if (count($buffer) == $total) {
$trigger = 0;
break;
}
$next = $styles[$k+1] ?? ($total - 1);
$next == $style ?: $buffer[] = $style;
}
}
print_r( $buffer );