当用户输入1000以上的数字时,我希望能够在数组中获得该数字的千位数.
例如…
用户输入的数字:165124
我的数组应该返回:
array('thousand_low' => 165000, 'thousand_high' = 165999)
Run Code Online (Sandbox Code Playgroud)
谢谢!
完整的数组返回函数,使用PHP的本机floor和ceil函数:
function get_thousands($num) {
return array(
'thousand_low'=>floor($num/1000)*1000,
'thousand_high'=>ceil($num/1000)*1000-1
);
}
Run Code Online (Sandbox Code Playgroud)