php sum of multiple outputs of the function -
i have following code:
<?php class test{ //here total price amount, , print-it on screen public function priceprod($amount){ if (!empty($amount)) { $price = 5; } //getting sum , outputed using echo $sum = $price * $amount; echo $sum.'<br>'; //building array $answer = array(); $answer['sum'] = $sum; } //here total price values outputed priceprod function public function sumprod(){ } //closing class } $test = new test; //feeding amount values function , getting multiple sums echo $test->priceprod(2); echo $test->priceprod(4); //getting total of sums echo $test->sumprod(); ?> how make function sumprod makes sum of outputs of function priceprod. now, if example of function not complete, seem take , output last value of $sum. if use database store values, think more simpler, raw output this, don't know how find answer.
any type of answers welcomed. thank much!
you should use array return value of function..
like.
$answer = array(); $answer['sum'] = $sum; $answer['price'] = $price; $answer['product'] = $product; return $answer;
Comments
Post a Comment