Skip to content

Instantly share code, notes, and snippets.

@epicsagas
Created April 12, 2019 05:41
Show Gist options
  • Save epicsagas/0ad6ba929937d4e1399c01efd7d7a3bf to your computer and use it in GitHub Desktop.
Save epicsagas/0ad6ba929937d4e1399c01efd7d7a3bf to your computer and use it in GitHub Desktop.
Korean won with Korean unit / 한국 금액을 한국어 단위로 처리
function createKoreanWon($price = 0)
{
$krw = '';
if($price) {
$priceArr = str_split(strrev((string)$price), 4);
$unitArr = ['','만','억','조','경'];
$count = min(count($priceArr),count($unitArr));
$priceWithUnit =
array_combine(
array_slice($unitArr, 0, $count),
array_slice($priceArr, 0, $count)
);
foreach(array_reverse($priceWithUnit) as $unit => $price) {
$price = intval(strrev($price));
$krw .= ($price > 0) ? $price . $unit : '';
}
}
return $krw . '원';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment