本文目錄一覽:
- 1、PHP 加法
- 2、PHP,簡單加法…
- 3、php加法計算器問題
- 4、php 加法bug
- 5、php加法問題
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);
原創文章,作者:O5HSM,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/130544.html