很多站长朋友们都不太清楚phpmath.min,今天小编就来给大家整理phpmath.min,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php如何把一个数分成N份 2、 php求助图片缩放裁切问题 3、 javascript里的Math.random() 函数, 在php里, 有类似的吗? 4、 怎么把如下php代码写成lua代码? 5、 php 计算经纬度之间相差多少公里 php如何把一个数分成N份大致思路
1)取份数的平均值
2)根据允许的各份数间最大差值,动态调整随机数范围,形成各份的数量
3)最后一份的数量由前面已经分出的决定,以保证各份的总和为指定值
代码如下:
<?php
$total = 100; //待划分的数字
$div = 5; //分成的份数
$area = 10; //各份数间允许的最大差值
$average = round($total / $div);
$sum = 0;
$result = array_fill( 1, $div, 0 );
for( $i = 1; $i < $div; $i++ ){
//根据已产生的随机数情况,调整新随机数范围,以保证各份间差值在指定范围内
if( $sum > 0 ){
$max = 0;
$min = 0 - round( $area / 2 );
}elseif( $sum < 0 ){
$min = 0;
$max = round( $area / 2 );
}else{
$max = round( $area / 2 );
$min = 0 - round( $area / 2 );
}
//产生各份的份额
$random = rand( $min, $max );
$sum += $random;
$result[$i] = $average + $random;
}
//最后一份的份额由前面的结果决定,以保证各份的总和为指定值
$result[$div] = $average - $sum;
//结果呈现
echo '划分情况:<br>';
foreach( $result as $temp ){
echo $temp, '<br>';
}
echo '总和:', array_sum( $result );
exit;
?>
php求助图片缩放裁切问题这段代码可以通过自已选择来决定图片的大小!
效果图如下所示:希望对你有帮助!
其中
minSize: [48,48],
setSelect: [0,0,190,190],
是调整选取范围的大小,若你 调整为120和160就改为了
setSelect: [0,0,120,160],
就可以了!
<?php
error_reporting(7);
date_default_timezone_set("Asia/Shanghai");
header("Content-type:text/html; Charset=utf-8");
require_once("./image.class.php");
$images = new Images("file");
if ($_GET['act'] == 'cut'){
$image = "/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg";
$res = $images->thumb($image,false,1);
if($res == false){
echo "裁剪失败";
}elseif(is_array($res)){
echo '<img src="'.$res['big'].'" style="margin:10px;">';
echo '<img src="'.$res['small'].'" style="margin:10px;">';
}elseif(is_string($res)){
echo '<img src="'.$res.'">';
}
}elseif(isset($_GET['act']) $_GET['act'] == "upload"){
$path = $images->move_uploaded();
$images->thumb($path,false,0); //文件比规定的尺寸大则生成缩略图,小则保持原样
if($path == false){
$images->get_errMsg();
}else{
echo "上传成功!<a href='".$path."' target='_blank'>查看</a>";
}
}else{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ";quot;;>
<html>
<head>
<meta name="Author" content="SeekEver">
<meta name="Keywords" content="">
<meta name="Description" content="">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<script src="./js/jquery.min.js" type="text/javascript"></script>
<script src="./js/jquery.Jcrop.js" type="text/javascript"></script>
<link rel="stylesheet" href="./css/jquery.Jcrop.css" type="text/css" />
<script type="text/javascript">
jQuery(function($){
// Create variables (in this scope) to hold the API and image size
var jcrop_api, boundx, boundy;
$('#target').Jcrop({
minSize: [48,48],
setSelect: [0,0,190,190],
onChange: updatePreview,
onSelect: updatePreview,
onSelect: updateCoords,
aspectRatio: 1
},
function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
// Store the API in the jcrop_api variable
jcrop_api = this;
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
function updatePreview(c){
if (parseInt(c.w) > 0)
{
var rx = 48 / c.w; //小头像预览Div的大小
var ry = 48 / c.h;
$('#preview').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
{
var rx = 199 / c.w; //大头像预览Div的大小
var ry = 199 / c.h;
$('#preview2').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
};
});
</script>
</head>
<body>
<form method="post" action="?act=upload" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="上传">
</form>
<div style="float:left;"><img id="target" src="/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<div style="width:48px;height:48px;margin:10px;overflow:hidden; float:left;"><img style="float:left;" id="preview" src="/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<div style="width:190px;height:195px;margin:10px;overflow:hidden; float:left;"><img style="float:left;" id="preview2" src="/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg" ></div>
<form action="index.php?act=cut" method="post" onsubmit="return checkCoords();">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" value="裁剪" />
</form>
</body>
</html>
<?php
}
?>
javascript里的Math.random() 函数, 在php里, 有类似的吗?<?php
function random($min = 0, $max = 1)
{
return $min + mt_rand()/mt_getrandmax()*($max-$min);
}
var_dump(random());
// 打印结果
float 0.79857454579257
?>
怎么把如下php代码写成lua代码?base64需要自己找个库调用一下,其他部分实现了,下面是代码
local function decode(str, skey)
str = str or ""
skey = skey or "cxphp"
local replaceStr = string.gsub(str, "O0O0O", "=")
replaceStr = string.gsub(replaceStr, "o000o", "+")
replaceStr = string.gsub(replaceStr, "oo00o", "/")
local strArr = {}
local replaceStrLen = string.len(replaceStr)
for pos = 1, replaceStrLen, 2 do
local posEnd = math.min(pos + 1, replaceStrLen)
strArr [#strArr + 1] = string.sub(replaceStr, pos, posEnd)
end
local strCount = #strArr
for key = 1, string.len(skey) do
local value = string.sub(skey, key, key)
print(key, value, strArr[key], string.sub(strArr[key], 2, 2))
if key <= strCount and strArr[key] and string.sub(strArr[key], 2, 2) == value then
strArr[key] = string.sub(strArr[key], 1, 1)
end
end
local needToDecode = table.concat(strArr)
print(needToDecode)
-- TODO: find a lib base64_decode
end
php 计算经纬度之间相差多少公里//php 计算地图上两个坐标之间的距离
define('EARTH_RADIUS', 6378.137);//地球半径,假设地球是规则的球体
define('PI', 3.1415926);
/**
* 计算两组经纬度坐标 之间的距离
* params :lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km);
* return m or km
*/
function GetDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)
{
$radLat1 = $lat1 * PI ()/ 180.0; //PI()圆周率
$radLat2 = $lat2 * PI() / 180.0;
$a = $radLat1 - $radLat2;
$b = ($lng1 * PI() / 180.0) - ($lng2 * PI() / 180.0);
$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));
$s = $s * EARTH_RADIUS;
$s = round($s * 1000);
if ($len_type --> 1)
{
$s /= 1000;
}
return round($s, $decimal);
}
echo GetDistance(39.908156,116.4767, 39.908452,116.450479, 1);//输出距离/米
关于phpmath.min的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于phpmath.min的简单介绍的详细内容...