Location: PHPKode > scripts > Math > math/addition.class.php
<?php
//This class will do mathmatical calculations
class math {
	//This function will calculate the addition of all of the values in the array!!
	function add_array($arr) {
		$finalNum = 0;
		foreach ($arr as $item) {
			$item = $this->remove_comma($item);
			if (!is_numeric($item)) {
				return false;
			}
		}
		for ($i = 0; $i < count($arr);) {
			$finalNum += $this->remove_comma($arr[$i]);
			 $i++;
		}
		return $this->add_comma($finalNum);
	}
	
	//This function will make sure that if there are any comma's in 
	//the numbers that they will be taken out!
	function remove_comma($num) {
		$num = explode(",", $num);
		$num = implode("", $num);
		return $num;
	}
	
	
	//This function will add the comma back in to a number to
	//prepare for display for the user
	function add_comma($num) {
		$num = number_format($num, 2);
		return $num;
	}
}

$math = new math();
?>
Return current item: Math