 <p>Here's an example that uses a function to add the elements, only if they don't already exist:</p> <pre><code> function addItems($items, $arr) { foreach($items as $value) { if(!in_array($value, $arr)) { $arr[] = $value; } } return $arr; } $res = array(); if(in_array("1", $mod)){ $res = addItems(array('First Name','Insertion','Last Name','Lead Country'), $res);} if(in_array("2", $mod)){ $res = addItems(array('Landline No:','Mobile No:','Lead Country'), $res);} if(in_array("3", $mod)){ $res = addItems(array('City','State','Country','Lead Country'), $res);} if(in_array("4", $mod)){ $res = addItems(array('Email','Lead Country'), $res);} return $res; </code></pre> <p>Here's another way of doing it which is more OOP and is probably a bit more logical because it doesn't keep passing the whole array back and to, instead it uses an object which holds the array, and has a method to add to it, and get the final result:</p> <pre><code> class ItemsManager { protected $items = array(); public function addItems($items) { foreach($items as $value) { if(!in_array($value, $this-&gt;items)) { $this-&gt;items[] = $value; } } } public function getItems() { return $this-&gt;items; } } $im = new ItemsManager(); if(in_array("1", $mod)){ $im-&gt;addItems(array('First Name','Insertion','Last Name','Lead Country'));} if(in_array("2", $mod)){ $im-&gt;addItems(array('Landline No:','Mobile No:','Lead Country'));} if(in_array("3", $mod)){ $im-&gt;addItems(array('City','State','Country','Lead Country'));} if(in_array("4", $mod)){ $im-&gt;addItems(array('Email','Lead Country'));} return $im-&gt;getItems(); </code></pre>