note 78757 deleted from language.functions by felipe

From: Date: Sun, 16 Dec 2007 11:33:47 +0000
Subject: note 78757 deleted from language.functions by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133664@lists.php.net to get a copy of this message
Note Submitter: SID TRIVEDI Reason: 1 ---- <?php /* Example of a simple arithmatic function returning mutliple values of variables retrning outside of a function by means of an array. */ $a = null;// variable definition and initial value assignment. $b =null; // variable definition and initial value assignment. function arithmatic($a,$b)// Here $a and $b as function argument - operands (to be operated upon. { global $sum; // global makes variable $sum available outside the function. global $array; // global makes variable $sum available outside the function. $sum = $a + $b; $dif = $a - $b; $mul = $a * $b; $div = bcdiv($a,$b,2);// division precision with 2 decimal points. $array = array($a, $b, $sum, $dif, $mul, $div); return $array; } arithmatic(11,5); // function call by values of $a and $b list($a, $b, $sum, $dif, $mul, $div) = $array; echo "$a plus $b equals to $sum.\n<br>"; echo "$a minus $b equals to $dif.\n<br>"; echo "$a multiplied by $b equals to $mul.\n<br>"; echo "$a divided by $b equals to $div.\n<br>"; /* This generates following output : 11 plus 5 equals to 16. 11 minus 5 equals to 6. 11 multiplied by 5 equals to 55. 11 divided by 5 equals to 2.20. */ ?>

« previous php.notes (#133664) next »