From e328ead4c57b65659589dc2dbb1d7b90d820200d Mon Sep 17 00:00:00 2001 From: Brian Gregg Date: Wed, 26 May 2021 14:44:42 -0400 Subject: [PATCH] Made some changes regarding array_push. --- src/Users/UserStatistics.php | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Users/UserStatistics.php b/src/Users/UserStatistics.php index a83d094..74c96e7 100644 --- a/src/Users/UserStatistics.php +++ b/src/Users/UserStatistics.php @@ -19,7 +19,21 @@ public function getStatistics() { $stats = array(); foreach ($this->data as $statistic) { - array_push($stats,$statistic); + $stats[] = $statistic; + } + return $stats; + } + + /** + * Get the user's statistics. + * + * @return array of statistics. + */ + public function get() + { + $stats = array(); + foreach ($this->data as $statistic) { + $stats[] = $statistic; } return $stats; } @@ -38,7 +52,7 @@ public function getStatistic($typeCode,$categoryCode) foreach ($this->data as $statistic) { if (($statistic->category_type->value == $typeCode) && ($statistic->statistic_category->value == $categoryCode)) { - array_push($stats,$statistic); + $stats[] = $statistic; } } return $stats; @@ -130,15 +144,22 @@ public function addStatistic($typeCode,$categoryCode,$segmentType,$note) */ public function removeStatistic($typeCode,$categoryCode) { - $max = sizeof($this->data); - $ret = false; - for($i = 0; $i < $max; $i++) { - if (($this->data[$i]->category_type->value == $typeCode) && ($this->data[$i]->statistic_category->value == $categoryCode)) { - unset($this->data[$i]); - $ret = true; + # Old way: + #$max = sizeof($this->data); + #for($i = 0; $i < $max; $i++) { + # if (($this->data[$i]->category_type->value == $typeCode) && ($this->data[$i]->statistic_category->value == $categoryCode)) { + # unset($this->data[$i]); + # $ret = true; + # } + #} + + # New way: (Thanks Rick!) + foreach($this->data as $key => $row) { + if (($row->category_type->value == $typeCode) && ($row->statistic_category->value == $categoryCode)) { + array_splice($this->data, $key, 1); } } - return($ret); + return; } /**