首页 > 编程知识 正文

一个php加法的问题(php加法运算)

时间:2023-12-09 23:11:59 阅读:313920 作者:ETLR

本文目录一览:

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; $istrlen($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,简单加法...

$a + $a ++ = $a + ($a ++)

第一步执行$a ++ :$x = $a = 2, $a = $a + 1 = 3

第二步执行 $a + ($a ++) = $a + $x = 3 + 2 = 5

php加法计算器问题

通过POST来判断,两个提交过来的价值,用+法对两个值进行相加。得出最后的值。

?php

if($_POST['sub']){

if(!empty($_POST['plus']) !empty($_POST['red'])){

$plus = $_POST['plus'];

$red = $_POST['red'];

$and = $plus+$red;

}else{

echo "所有数值均不能为空";

}

}

?

form action="" method="POST"

input type="text" name="plus" value="?php echo $plus?"+

input type="text" name="red" value="?php echo $red?"

input type="submit" name="sub" value="等于"

input type="text" value="?php echo $and?"

/form

php 加法bug

建议你先把 time()的值给一个变量,然后再操作。

$timemark=time();

$newtimemark=$timemark+3600*24*14;

echo $newtimemark;

php加法问题

echo $strHealthRecordPrice + $countPrice;

改为

echo floatval($strHealthRecordPrice) + floatval($countPrice);

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。