本文整理汇总了PHP中multiply函数的典型用法代码示例。如果您正苦于以下问题:PHP multiply函数的具体用法?PHP multiply怎么用?PHP multiply使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了multiply函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
<?php
function add($a, $b)
{
return $a + $b;
}
function subtract($a, $b)
{
return $a - $b;
}
function multiply($a, $b)
{
return $a * $b;
// Add code here
}
function divide($a, $b)
{
return $a / $b;
}
// Add code to test your functions here
echo add(4, 5);
echo subtract(18, 9);
echo multiply(3, 3);
echo divide(18, 3);
示例2: multiply
function multiply($x, $y)
{
if ($y == 1) {
return $x;
}
return $x + multiply($x, $y - 1);
}
示例3: multiply
function multiply($n, $m)
{
if ($m == 1) {
return $n;
}
return $n + multiply($n, $m - 1);
}
示例4: promptDivide
function promptDivide()
{
$a = prompt("Enter a number (a) that you'd like to divide:");
$b = prompt("Enter a number (b) that you'd like to divide by:");
$c = prompt("Enter a number (c) that you'd like to multiply by:");
return Attempt::call('divide', array($a, $b))->map(function ($elem) use($c) {
return multiply($elem, $c);
});
}
示例5: mathOperation
function mathOperation($arg1, $arg2, $operation)
{
switch ($operation) {
case 'add':
echo adding($arg1, $arg2);
break;
case 'substract':
echo substracting($arg1, $arg2);
break;
case 'multiply':
echo multiply($arg1, $arg2);
break;
case 'divide':
echo divide($arg1, $arg2);
break;
default:
echo "Вы не корректно определили параметры!";
break;
}
}
示例6: multiply
<?php
/*this is an example on global variable*/
$x = 5;
$y = 10;
function multiply($x, $y)
{
echo $GLOBALS['x'] * $y;
}
multiply(3, 3);
//Output: 15
示例7: multiply
<?php
// multiplicar un valor por diez y retornarlo al invocador
function multiply($value)
{
$value = $value * 10;
return $value;
}
$retval = multiply(10);
print "Return value is {$retval}\n";
?>
示例8: multiply
<?php
function multiply($a, $b)
{
$a * ($b = $c);
return $c;
}
$newNumber = multiply(5, 6);
echo $newNumber;
echo "hello";
?>
<h1> Hello </h1>
示例9: modulus
} else {
echo "ERROR: Cannot divide by 0\n";
}
}
}
function modulus($a, $b)
{
$error = errorCheck($a, $b);
if ($error) {
if ($a != 0 && $b != 0) {
return $a % $b;
} else {
echo "ERROR: Cannot divide by 0\n";
}
}
}
function errorCheck($a, $b)
{
if (!is_numeric($a) || !is_numeric($b)) {
echo "ERROR: Both arguments must be numbers\n";
return false;
} else {
return true;
}
}
// Add code to test your functions here
echo add(10, 2) . PHP_EOL;
echo subtract(10, 2) . PHP_EOL;
echo multiply(10, 2) . PHP_EOL;
echo divide(10, 2) . PHP_EOL;
echo modulus(10, 2) . PHP_EOL;
示例10: multiply
<?php
$result = 0;
if (isset($_GET["multiply_numbers"])) {
$result = multiply($_GET["var_one"], $_GET["var_two"]);
}
function multiply($x, $y)
{
$answer = $x * $y;
return $answer;
}
?>
<form method="get" >
<input name="var_one"> * <input name="var_two">
<input name="multiply_numbers" type="submit">
<form>
<p>Answer is <?php
echo $result;
?>
</p>
示例11: array
<?php
$array = array(2, 4, 10, 16);
function multiply($array, $num)
{
$result = array();
foreach ($array as $key) {
$product = $key * $num;
array_push($result, $product);
}
var_dump($result);
}
multiply($array, 5);
示例12: multiply
<?php
echo '<h1>De uitkomst van de vermenigvuldiging:</h1>
<h2>' . $valA . ' x ' . $valB . ' = ' . multiply($valA, $valB) . '</h2>';
示例13: modulus
{
if ($b == 0) {
return 'ERROR: You are trying to destroy us all! ' . $a . ' ' . $b;
}
// $isValid = errorMessage($a, $b);
if (validate($a, $b)) {
return $a / $b;
}
// } else {
// return $isValid;
// }
}
function modulus($a, $b)
{
if ($b == 0) {
return 'ERROR: You are trying to destroy us all! ' . $a . ' ' . $b;
}
// $isValid = errorMessage($a, $b);
if (validate($a, $b)) {
return $a % $b;
}
// } else {
// return $isValid;
// }
}
echo add(9, "notNumeric") . PHP_EOL;
echo subtract(9, 3) . PHP_EOL;
echo multiply(9, 3) . PHP_EOL;
echo divide(9, 0) . PHP_EOL;
echo modulus(9, 3) . PHP_EOL;
// Add code to test your functions here
示例14: operators
/*
Using this regex we can split the string into an array based on the 4 math operators (+,-,/,*).
PREG_SPLIT_DELIM_CAPTURE returns the operators as part of the array.
*/
$stack = preg_split('/ *([+\\-\\/*]) */', $question, -1, PREG_SPLIT_DELIM_CAPTURE);
//The stack array must have a minimum of 3 elements to form a valid math operation: [A] [OPERATOR] [B]
while (sizeof($stack) >= 3) {
switch ($stack[1]) {
case "+":
$answer = addition($stack[0], $stack[2]);
break;
case "-":
$answer = subtract($stack[0], $stack[2]);
break;
case "*":
$answer = multiply($stack[0], $stack[2]);
break;
case "/":
$answer = divide($stack[0], $stack[2]);
break;
}
//Remove the first 3 elements from the stack as they have been processed
$stack = array_slice($stack, 3);
//Add the current answer total to the beginning of the array for any further processes
array_unshift($stack, $answer);
}
function addition($val1, $val2)
{
return $val1 + $val2;
}
function subtract($val1, $val2)
示例15: array
<?php
$A = array(2, 4, 10, 16);
//$n = 0;
function multiply($A, $n)
{
$B = array();
foreach ($A as $values) {
$B[] = $values * $n;
}
var_dump($B);
}
multiply($A, 5);