php四舍五入法、进一取整及舍去取整的例子,供初学php的朋友参考。
一、round() 四舍五入法
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.04
echo round(5.055, 2); // 5.06
?>
2、ceil() 进一法取整法
echo ceil(4.3); // 5
echo ceil(9.999); // 10
?>
3、floor() 舍去法取整法
echo floor(4.3); // 4
echo floor(9.999); // 9
?>
php合并数组的函数array_merge应用实例,供大家学习参考。
<?php
//var_dump($_POST['description']);
if($type=="1"){
$arr1 = array(
"mcou" => $_POST['mcou'],
"scou" => $_POST['scou']
);
}else if($type=="2"){
$arr1 = array(
"yjcou" => $_POST['yjcou'],
"dzcou" => $_POST['dzcou']
);
}else if($type=="3"){
$arr1 = array(
"dycou" => $_POST['dycou']
);
}
$arr2 = array(
"name" => getstr($_POST['name'], 30, 1, 1, 1) ,
"classid" => intval($_POST['classid']),
"typeid" => intval($_POST['type']),
"storeid" => intval($_POST['storeid']),
"integral"=> intval($_POST['integral']),
"effect" => $_POST['effect'],
"recommend" =>intval($_POST['recommend']),
"introduct" => getstr($_POST['introduct'], 0, 1, 1, 1) ,
"valid" => getstr($_POST['valid'], 10, 1, 1, 1) ,
"displayorder" => intval($_POST['displayorder']),
"lastupdate" => $_JOYEGB['timestamp']
);
$arr = array_merge($arr1,$arr2);
?>
两个自定义函数,一是多维数组转字符串的函数arrayToString(),一个是多维数组转一维数组的函数multi2array(),供大家学习参考了。
<?php
/**
* @method 多维数组转字符串
* @staticvar array $result_array
* @param type $array
* @return type
* @link www.
*/
function arrayToString($arr)
{
if (is_array($arr))
{
return implode(',', array_map('arrayToString', $arr));
}
return $arr;
}
/**
* @method 多维数组变成一维数组
* @staticvar array $result_array
* @param type $array
* @return type
* @link www.
*/
function multi2array($array) {
static $result_array = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
array_multi2array($value);
}
else
$result_array[$key] = $value;
}
return $result_array;
}