Simple implementation of addition, subtraction, multiplication and division calculator using PHP_PHP tutorial
Use php to implement addition, subtraction, multiplication and division calculator. The code is very simple! The code is as follows: <?php header(“content-type:text/html;charset=utf-8”); session_start(); ?> The first number Calculation symbol + – * / The second number <?php $num1=$_POST[‘num1’]; $num2=$_POST[‘num2’]; $oper=$_POST[‘oper’]; $rs=0; switch($oper){ case “+”: $rs=$num1+$num2; break; case “-“: $rs=$num1-$num2; break; case “*”: $rs=$num1*$num2; break; case “/”: $rs=$num1/$num2; break; default: echo “Your input is incorrect”; } $ _SESSION[‘rs’]=$rs; echo ‘The calculation result is: ‘.$_SESSION[‘rs’]; ?> http://www.bkjia.com/PHPjc/676921.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/676921.htmlTechArticleUse PHP to implement addition, subtraction, multiplication and division calculator. The code is very simple! The code is as follows: ?php header(“content-type:text/html;charset=utf-8”); session_start(); ? !DOCTYPE html PUBLIC “-/…
Simple implementation of addition, subtraction, multiplication and division calculator using PHP
The first number Calculation symbols + – * / The second number
Simple implementation of addition, subtraction, multiplication and division calculator using php_php skills
Use php to implement addition, subtraction, multiplication and division calculator. The code is very simple! The code is as follows: <? php header(“content-type:text/html;charset=utf-8”); session_start(); ?> First number Calculation symbol + – * / The second number <?php $num1=$_POST[‘num1’]; $num2=$_POST[‘num2’]; $oper=$_POST[‘oper’]; $rs =0; switch($oper){ case “+”: $rs=$num1+$num2; break; case “-“: $rs= $num1-$num2; break; case “*”: $rs=$num1*$num2; break; case “/”: $rs= $num1/$num2; break; default: echo “Your input is incorrect”; } $_SESSION[‘rs’]=$rs; echo ‘Calculation results For: ‘.$_SESSION[‘rs’]; ?>
(PHP implementation) Only use ++ operations to implement addition, subtraction, multiplication, and division_php tips
Addition The code is as follows: function jiafa($a,$b){ for($i=0;$i<$b;$i++) { $a++; } return $a;}//echo jiafa(4,2); Subtraction The code is as follows: function jianfa($a,$b ){ $c=0; while($b!=$a) { $b++; $c++; } echo $ c;} // end func//jianfa(10,3); Multiplication The code is as follows: function chengfa($a,$b) { $c=0; for($j=0;$j<$b;$j++) { $c=jiafa($c,$a); } return $c;} // end func//chengfa(9,3); Division The code is as follows: function chufa($d, $e){ $k=0; $f=0; while($f<$d) { $k++; $f= chengfa($e,$k); } return $k;} // end funcecho chufa(16,2);
PHP’s chr and ord functions implement character addition, subtraction, multiplication and division operations code_php skills
The chr function is used to convert ASCII codes into charactersord function is used to convert characters into ASCII codes ASCII code is the encoding of characters that the computer can display, and its value range is 0-255. These include punctuation, letters, numbers, Chinese characters, etc. During the programming process, specified characters are often converted into ASCII codes for comparison. The following is a function provided by PHP to convert ASCII codes and characters. 1. chr() function This function is used to convert ASCII code values into strings. The function declaration is as follows: string chr (int ascii); 2. ord() function This function is used to convert a string into an ASCII code value. The function declaration is as follows: int ord(string str); Example: Use the chr() function and ord() function to perform conversion operations between strings and ASCII codes. The program code is as follows: The code is as follows: <?php $str1=chr(88); echo $str1; //The return value is X $str2=chr(ord(X)+1); // echo $str2; / /The return value is Y echo “\t”; $str3=ord(‘S’); echo $str3; //The return value is 83 ?> Run result: X Y 83
Simple implementation of addition, subtraction, multiplication and division calculator using PHP_PHP
Use php to implement addition, subtraction, multiplication and division calculator. The code is very simple! The code is as follows: <?php header(“content-type:text/html;charset=utf-8”); session_start(); ?> The first number Calculation symbol + – * / The second number <?php $num1=$_POST[‘num1’]; $num2=$_POST[‘num2’]; $oper=$_POST[‘oper’]; $rs=0; switch($oper){ case “+”: $rs=$num1+$num2; break; case “-“: $rs=$num1-$num2; break; case “*”: $rs=$num1*$num2; break; case “/”: $rs=$num1/$num2; break; default: echo “Your input is incorrect”; } $_SESSION[‘rs’]=$rs; echo ‘The calculation result is:’.$_SESSION[‘rs’]; ?>
PHP’s chr and ord functions implement character addition, subtraction, multiplication and division operations code_PHP
The chr function is used to convert ASCII codes to charactersord function is used to convert characters to ASCII codes ASCII codes are the codes of characters that can be displayed by the computer, and its value range is 0-255. These include punctuation, letters, numbers, Chinese characters, etc. In the programming process, the specified characters are often converted into ASCII codes for comparison. The following is the function provided by PHP to convert ASCII codes and characters. 1. chr() function This function is used to convert the ASCII code value into a string. Its function is declared as follows: string chr (int ascii); 2. ord() function This function is used to convert a string into an ASCII code value. Its function declaration is as follows: int ord(string str); Example: Use chr() function and ord() function to perform the conversion operation between string and ASCII code, the program code is as follows: The code is as follows: <?php $str1=chr(88); echo $str1; //The return value is X $str2=chr( ord(X)+1); // echo $str2; //The return value is Y echo “\t”; $str3=ord(‘S’); echo $ str3; //The return value is 83 ?> Running result: X Y 83
PHP dynamic addition, subtraction, multiplication and division
$a = 1; $b = 1; $c = ‘-‘; echo $a.$c.$b;//1+1 How to implement $a.$c.$b to output 0? Is it possible to implement dynamic calculation results of addition, subtraction, multiplication and division? Response content: $a = 1; $b = 1; $c = ‘-‘; echo $a.$c.$b;//1+1 How to implement $a.$c.$b to output 0? Is it possible to implement dynamic calculation results of addition, subtraction, multiplication and division? echo eval(“return {$a}{$c}{$b};”); About eval, refer to the documentation echo $a.’-‘.$b.’=’.($a-$b); switch($c){case ‘+’:echo $a+$b;break;case ‘-‘:echo $a-$b;break; >case ‘*’:echo $a*$b;break;case ‘/’:echo $a/$b;break;default:echo “Input error “;}
PHP dynamic addition, subtraction, multiplication and division
$a = 1; $b = 1; $c = ‘-‘; echo $a.$c.$b;//1+1 How to implement $a.$c.$b to output 0? Is it possible to implement dynamic calculation results of addition, subtraction, multiplication and division? Response content: $a = 1; $b = 1; $c = ‘-‘; echo $a.$c.$b;//1+1 How to implement $a.$c.$b to output 0? Is it possible to implement dynamic calculation results of addition, subtraction, multiplication and division? echo eval(“return {$a}{$c}{$b};”); About eval, refer to the documentation echo $a.’-‘.$b.’=’.($a-$b); switch($c){case ‘+’:echo $a+$b;break;case ‘-‘:echo $a-$b;break; >case ‘*’:echo $a*$b;break;case ‘/’:echo $a/$b;break;default:echo “Input error “;}
PHP’s chr and ord functions implement character addition, subtraction, multiplication, and division operations to achieve code
What is the use of these two functions? It is most suitable for character addition and subtraction. Ordinary characters cannot be added or subtracted to point to the next character. After converting to ASCII Can do addition, subtraction, multiplication and addition. After processing, it can be converted into characters. Many current string encryption and decryption use this function! The chr function is used to convert ASCII codes to charactersord function is used to convert characters to ASCII codes ASCII codes are the codes of characters that can be displayed by the computer, and its value range is 0-255. These include punctuation, letters, numbers, Chinese characters, etc. In the programming process, the specified characters are often converted into ASCII codes for comparison. The following is the function provided by PHP to convert ASCII codes and characters. 1. chr() function This function is used to convert the ASCII code value into a string. Its function is declared as follows: string chr (int ascii); 2. ord() function This function is used to convert a string into an ASCII code value. Its function declaration is as follows: int ord(string str); Example: Use the chr() function and ord() function to perform conversion operations between strings…