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'])) { // A single ID $this->filters['id'] = $ids; } else { // Multiple IDs. Append new 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([4,3,2,1,0]); var_dump($filter->getFilters());
Output for 5.6.38
array(1) { ["id"]=> array(6) { [0]=> int(1) [1]=> int(22) [2]=> int(4) [3]=> int(3) [4]=> int(2) [6]=> int(0) } }