It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.
If the size of the collection does not change during the iteration, it is
generally a good practice to compute it beforehand, and not on each iteration:
for($i=0;$i<count($array);$i++){// calls count() on each iteration}// Betterfor($i=0,$c=count($array);$i<$c;$i++){// calls count() just once}
Loading history...
30
if ($this->list[$i]->parent_item_id == $parentId) {
31
$list->add($this->list[$i]);
32
}
33
}
34
35
return $list;
36
}
37
38
/**
39
* @param array $list
40
*/
41
public function add($list)
42
{
43
$this->list[] = $list;
44
}
45
46
/**
47
* @return array
48
*/
49
public function getListOfParents()
50
{
51
$result = [];
52
foreach ($this->list as $item) {
53
if (!in_array($item->parent_item_id, $result)) {
54
$result[] = $item->parent_item_id;
55
}
56
}
57
58
return $result;
59
}
60
61
/**
62
* @param int $id
63
* @param int $value
64
* @param string $parameter
65
*/
66
public function setParametersForId($id, $value, $parameter)
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.
If the size of the collection does not change during the iteration, it is
generally a good practice to compute it beforehand, and not on each iteration:
for($i=0;$i<count($array);$i++){// calls count() on each iteration}// Betterfor($i=0,$c=count($array);$i<$c;$i++){// calls count() just once}
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: