1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8class Math_Formula_Function_Div extends Math_Formula_Function 9{ 10 function evaluate($element) 11 { 12 $elements = []; 13 14 foreach ($element as $child) { 15 $evaluatedChild = $this->evaluateChild($child); 16 $elements[] = ! empty($evaluatedChild) ? $evaluatedChild : 0; 17 } 18 19 $out = array_shift($elements); 20 21 foreach ($elements as $element) { 22 if ($element && is_numeric($out) && is_numeric($element)) { 23 $out /= $element; 24 } else { 25 Feedback::warning(tr('Divide by zero on "%0"', implode(',', $elements))); 26 $out = false; 27 } 28 } 29 30 return $out; 31 } 32} 33