Skip to content

Commit e328ead

Browse files
committed
Made some changes regarding array_push.
1 parent c20ab1f commit e328ead

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/Users/UserStatistics.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ public function getStatistics()
1919
{
2020
$stats = array();
2121
foreach ($this->data as $statistic) {
22-
array_push($stats,$statistic);
22+
$stats[] = $statistic;
23+
}
24+
return $stats;
25+
}
26+
27+
/**
28+
* Get the user's statistics.
29+
*
30+
* @return array of statistics.
31+
*/
32+
public function get()
33+
{
34+
$stats = array();
35+
foreach ($this->data as $statistic) {
36+
$stats[] = $statistic;
2337
}
2438
return $stats;
2539
}
@@ -38,7 +52,7 @@ public function getStatistic($typeCode,$categoryCode)
3852
foreach ($this->data as $statistic) {
3953
if (($statistic->category_type->value == $typeCode) &&
4054
($statistic->statistic_category->value == $categoryCode)) {
41-
array_push($stats,$statistic);
55+
$stats[] = $statistic;
4256
}
4357
}
4458
return $stats;
@@ -130,15 +144,22 @@ public function addStatistic($typeCode,$categoryCode,$segmentType,$note)
130144
*/
131145
public function removeStatistic($typeCode,$categoryCode)
132146
{
133-
$max = sizeof($this->data);
134-
$ret = false;
135-
for($i = 0; $i < $max; $i++) {
136-
if (($this->data[$i]->category_type->value == $typeCode) && ($this->data[$i]->statistic_category->value == $categoryCode)) {
137-
unset($this->data[$i]);
138-
$ret = true;
147+
# Old way:
148+
#$max = sizeof($this->data);
149+
#for($i = 0; $i < $max; $i++) {
150+
# if (($this->data[$i]->category_type->value == $typeCode) && ($this->data[$i]->statistic_category->value == $categoryCode)) {
151+
# unset($this->data[$i]);
152+
# $ret = true;
153+
# }
154+
#}
155+
156+
# New way: (Thanks Rick!)
157+
foreach($this->data as $key => $row) {
158+
if (($row->category_type->value == $typeCode) && ($row->statistic_category->value == $categoryCode)) {
159+
array_splice($this->data, $key, 1);
139160
}
140161
}
141-
return($ret);
162+
return;
142163
}
143164

144165
/**

0 commit comments

Comments
 (0)