Mariusz Muszyński 7 年之前
父节点
当前提交
0036595728
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      SE/se-lib/Benford.php

+ 6 - 2
SE/se-lib/Benford.php

@@ -45,7 +45,9 @@ class Benford {
 			$this->benford['firstStep'][$s[0]]['keys'][] = $k;
 		}
 
-		foreach ($this->benford['firstStep'] as $k => $v) {
+		for ($k = 1; $k <= 9; $k++) {
+			if (!isset($this->benford['firstStep'][$k])) $this->benford['firstStep'][$k]['keys'] = [];
+			$v = $this->benford['firstStep'][$k];
 			$this->benford['firstStep'][$k]['count'] = count($v['keys']);
 			$this->benford['firstStep'][$k]['value'] = count($v['keys']) / count($this->array);
 			$this->benford['firstStep'][$k]['norm'] = self::benford($k);
@@ -77,7 +79,9 @@ class Benford {
 			$this->benford['secondStep'][$a][$s[1]]['keys'][] = $k;
 		}
 
-		foreach ($this->benford['secondStep'][$a] as $k => $v) {
+		for ($k = 0; $k <= 9; $k++) {
+			if (!isset($this->benford['secondStep'][$a][$k])) $this->benford['secondStep'][$a][$k]['keys'] = [];
+			$v = $this->benford['secondStep'][$a][$k];
 			$this->benford['secondStep'][$a][$k]['count'] = count($v['keys']);
 			$this->benford['secondStep'][$a][$k]['value'] = count($v['keys']) / count($this->array);
 			$this->benford['secondStep'][$a][$k]['norm'] = self::benford($a * 10 + $k);