3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php Class Filter { private $filters = []; public function addIds($ids) { if (empty($this->filters['id'])) { $this->filters['id'] = $ids; } else { // Append new ids /* if (!is_array($this->filters['id'])) { $this->filters['id'] = [$this->filters['id']]; } if (!is_array($ids)) { $ids = [$ids]; } */ // $this->filters['id'] = (array)$this->filters['id'] + (array)$ids; $this->filters['id'] = array_unique(array_merge( (array)$this->filters['id'], (array)$ids )); } } public function getFilters() { return $this->filters; } } $filter = new Filter(); $filter->addIds(1); $filter->addIds(22); $filter->addIds(2); $filter->addIds([1,2,3,4]); //$filter->addIds([4,3,2,1,0]); var_dump($filter->getFilters());
Output for 5.6.38
array(1) { ["id"]=> array(5) { [0]=> int(1) [1]=> int(22) [2]=> int(2) [5]=> int(3) [6]=> int(4) } }