function circle_radius($center_point, $edge_point) { $center_point = array_altkey($center_point, array('x', 'y')); $edge_point = array_altkey($edge_point, array('x', 'y')); return sqrt(pow($edge_point[0] - $center_point[0], 2) + pow($edge_point[1] - $center_point[1], 2)); }
function set($set, $add = true) { if (is_array($set[0])) { foreach ($set as $value) { $this->set($value, $add); } } else { $temp = array_altkey($set, array('table', 'field', 'value')); if (is_array($temp[2])) { $temp[2] = array_altkey($temp[2], array('table', 'field')); } if ($add) { $this->set[$temp[0]][$temp[1]] = $temp[2]; } else { unset($this->set[$temp[0]][$temp[1]]); } } }
function str_check($string, $settings = array()) { if (!is_string($string)) { $string = (string) $string; } $checks = array_altkey($settings, array('min', 'max', 'regexp')); $strlen = strlen($string); $results = array(); if (isset($checks[0]) && isset($checks[1]) && $checks[0] == $checks[1]) { if ($strlen != $checks[0]) { $results[] = 'Not exactly ' . $checks[0] . ' characters.'; } } else { if (isset($checks[0]) && $strlen < $checks[0]) { $results[] = 'Less than ' . $checks[0] . ' characters.'; } if (isset($checks[1]) && $strlen > $checks[1]) { $results[] = 'More than ' . $checks[1] . ' characters.'; } } if (isset($checks[2]) && preg_match($checks[2], $string)) { $results[] = 'Does not match allowed characters rule.'; } if (empty($results)) { return false; } else { return $results; } }