* @package Mammut */ /* $Id$ */ (defined('MAMMUT') && (basename(__FILE__) != basename($_SERVER['PHP_SELF']))) or die('ACCESS DENIED'); /** * Calculates the average of all array values */ function array_avg(array $data) { if(count($data) == 0) return false; return (array_sum($data) / count($data)); } /** * Reads an array from a file * * Parses an file as php, and returns a array defined in the file, throwing away all * other variables. * * @param string $file * of the file * @param string $varname * of the variable that should be returned * @return array variable or false if variable is not set */ function array_from_file($file, $varname) { if(!include_exists($file)) throw new \Mammut\IO\FileNotFoundException($file); include ($file); if(isset(${$varname}) && is_array(${$varname})) return ${$varname}; else return false; } /** * Compares the content of two arrays. * By default, it checks if all values of A exist in B. If strict is set to * TRUE, the keys are compared, too. * * @param array $a * an array * @param array $b * another array to compare with the first one * @param string $strict * use strict comparing * @return boolean TRUE if both arrays are identical */ function array_compare(array $a, array $b, $strict = false) { foreach($a as $key => $value) { if (!$strict) { if(!in_array($value, $b)) return false; } else { if (!isset($b[$key]) || $b[$key] !== $value) return false; } } return true; }