Skip to content

Commit

Permalink
Made some changes regarding array_push.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdgregg committed May 26, 2021
1 parent c20ab1f commit e328ead
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/Users/UserStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit e328ead

Please sign in to comment.