很多站长朋友们都不太清楚php大整数加法,今天小编就来给大家整理php大整数加法,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP 加法 2、 PHP 中如何进行 长16进制的字符串运算? 3、 php里怎样将多个数字进行相加依次相加 4、 PHP加法乘法运算 5、 请问,在PHP里 如何把 123456 这相的一组数字 逐一相加呢? 6、 php里怎样将多个数字进行相加依次相加,如1-10全部加起来总和? PHP 加法涉及到进位问题,请问LZ, z+1=?
如果z+1=a的话:
<?php
$str = 'abcd';
$match = 225;
// 基础数据
// a-1,b-2,c-3,d-4....以此类推
for ($i=1; $i<=26; $i++) {
$base[$i] = chr(ord('a') + $i-1);
}
// 将字符串打散成数组
$str_new = array();
for ($i=0; $i<strlen($str); $i++) {
$a = strtolower(substr($str, $i, 1));
foreach ($base as $key=>$value) {
if ($a == $value) {
$str_new[] = $key;
}
}
}
// 执行
$temp = array();
$temp = do_add($str_new, $match, $temp);
// 将数组重新还原成字符串
$result = '';
for ($i=count($temp)-1; $i>=0; $i--) {
$a = $temp[$i];
foreach ($base as $key=>$value) {
if ($a == $key) {
$result .= $value;
}
}
}
// 输出
echo $result;
// 2个基础函数
function do_add($data_array, $match, $result) {
$result[] = ($data_array[count($data_array)-1] + $match) % 26 == 0 ? 26 : ($data_array[count($data_array)-1] + $match) % 26;
$match = ($data_array[count($data_array)-1] + $match) / 26 <= 1 ? 0 : floor(($data_array[count($data_array)-1] + $match) / 26);
array_pop($data_array);
if (count($data_array) != 0) {
return do_add($data_array, $match, $result);
} else {
$result = do_add_plus($match, $result);
return $result;
}
}
function do_add_plus($match, $result) {
$result[] = $match % 26 == 0 ? 1 : $match % 26;
$match = $match / 26 <= 1 ? 0 : floor($match / 26);
if ($match > 0) {
return do_add_plus($match, $result);
} else {
return $result;
}
}
?>
======================================================
PHP 中如何进行 长16进制的字符串运算?大整数需要用GMP模块,或者自己算法好可以写简单的累加,
在php.ini中开启模块extension=php_gmp.dll
<?php
$n = gmp_init('58915248108339c6ddca5553e9f266124e7af7c8',16); //16进制输入
$n = gmp_add($n,1); //加1
echo gmp_strval($n,16).'<br/>'; //16进制显示
$n = gmp_add($n,13869656); //加法
echo gmp_strval($n,16).'<br/>'; //16进制显示
输出
58915248108339c6ddca5553e9f266124e7af7c9
58915248108339c6ddca5553e9f266124f4e9a21
php里怎样将多个数字进行相加依次相加在while上面定义一个变量 $num = 0; 然后在里面在while里面加上去 $num = 0;while($row = mysql_fetch_array($query)){$a=$row["zhong"];$b=$row["shuliang"];$c=$a*$b;$num = $num + $c;echo $c.'';}echo $num;
PHP加法乘法运算以下代码,可以直接运行
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="yi" />
</label>一
<p>
<label>
<input type="text" name="er" />
</label>
二</p>
<p>
<label>
<input type="text" name="san" />
</label>
三</p>
<p>结果:
<?php
if($_POST['yi'] $_POST['er'] $_POST['san']){
$yi = $_POST['yi'];
$er = $_POST['er'];
$san = $_POST['san'];
echo $yi.'*1+'.$er.'*2+'.$san.'*3=';
echo $yi*1+$er*2+$san*3;
}
?>
</p>
<p>
<label>
<input type="submit" name="Submit" value="计算" />
</label>
</p>
</form>
</body>
</html>
请问,在PHP里 如何把 123456 这相的一组数字 逐一相加呢?for循环。
复制楼上的。
for($i=1;$i<=6;$i++){
$x+=$i;
}
echo $x;
可能看不懂$x+=$i;这个吧。。
这里的$x+=$i;相当于。。$x=$i+$x;
$i依次加一。
php里怎样将多个数字进行相加依次相加,如1-10全部加起来总和?这个就是看你数学的水平了 1加到10公共有5个11,如1+10=11;2+9=11;3+8=11。。。。这个公式用代码实现就是<?php
$a=1;
$b=10;
$num=($a+$b)*($b/2);
?>
关于php大整数加法的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php大整数加法 php加法函数的详细内容...