I am in doubt what to use:
foreach(){
// .....
if(!in_array($view, $this->_views[$condition]))
array_push($this->_views[$condition], $view);
// ....
}
OR
foreach(){
// .....
array_push($this->_views[$condition], $view);
// ....
}
$this->_views[$condition] = array_unique($this->_views[$condition]);
UPDATE
The goal is to get array of unique values. This can be done by checking every time if value already exists with in_array
or add all values each time and in the end use array_unique
. So is there any major difference between this two ways?
array_unique
removes duplicate values within a given array...in_array
provides a search into the array values and returns a true/false if found/not found – Congressin_array
or add all values each time and after usearray_unique
– WonderingO(n) + O(n log(n))
rather thanO(n^2)
for checkingin_array
each time – Monjo