Header Ads

PHP 수치 연산자


/*
+ 더하기
- 빼기
* 곱하기
/ 나누기
% 나머지
*/

$a = 10;
$b = 4;

function calc($a,$b,$x)
{
// if ($x=="plus") { return $a + $b; }
 switch($x)
 {
  case "plus":
  return $a + $b;
  break;
  
  case "minus":
  return $a - $b;
  break;
 
  case "times":
  return $a * $b;
  break;

  case "divides":
  return $a / $b;
  break;

  case "leaves":
  return $a % $b;
  break;
 }
}
echo calc($a,$b,"plus");
echo calc($a,$b,"minus");
echo calc($a,$b,"times");
echo calc($a,$b,"divides");
echo calc($a,$b,"leaves");

No comments

Copyright 2016, minki. All rights reserved. Powered by Blogger.