3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result = [ ["Apple iPhone 13 128 Go Minuit", "1 379€00"], ["Apple iPhone 14 128 Go Minuit", "1 379€00"], ["Apple iPhone 14 128 Go Lumière Stellaire", "919€00"], ["Apple iPhone 14 Pro 128 Go Noir Sidéral", "919€00"] ]; foreach ($result as $item) { $price = $item['1']; $convert_array = ['$', '€', '£', '¥', '₩', '₹', '₽', '฿', '₺', '₴']; foreach ($convert_array as $symbol) { if (strpos($price, $symbol) !== false) { $price = str_replace($symbol, '.', $price); $price = preg_replace('/\. /', '', $price, 1); $price = str_replace(',', '.', $price); break; } } $price_format = trim($price); if (substr($price_format, -1) == '.') { $price_format = substr($price_format, 0, -1); } if (is_string($price_format)) { $price_format = number_format((float)str_replace(' ','',$price_format), 2, '.', ' '); } if (is_numeric($price_format)) { $price_format = $price_format . ' num'; } print_r($price_format); echo PHP_EOL; }

preferences:
26.37 ms | 411 KiB | 5 Q