Search Marketing

   
   

Multiple Variables in a Custom Function

Fri May 02, 2008 10:04 pm
<<     >>
Comments: 0 Views: 2072
Creating PHP functions to accept two or more variables.

1. Create a function for multiplying an array of numbers by a random number.

function Add_Numbers($num,$multiplier)
{
$x = $num * $multiplier;
return($x);
}

$numbers = array(1,4,22,11,21,34,93);
$rand = rand(1,5);
$count = count($numbers);

$x = "";

for($i=0;$i<$count;$i++)
{
$x .= Add_Numbers($numbers[$i],$rand)." - ";
}

echo $x;

produces something like: 3 - 12 - 66 - 33 - 63 - 102 - 279

because the multiplier is random the results may be different.

The rand() function also requires two variables. The first number is the start and the second number is the end of the range. rand(1,5) will produce a random number between 1 and 5.



Comments
Name:
*
URL: http: (ex. cnn.com)
Comment:
*
Number:
Math (21 + 2)
* required
SubCategories
Regular Expressions

© 2019 Christonium LLC

Christonium.com
|
Terms of Use
|
Privacy
ccc