Very little handy code to remove duplicate elements from php associative array.

If you do have an array like below:

Array
(
    [0] => Array
	(
	    [0] => abc
	    [1] => def
	)

    [1] => Array
	(
	    [0] => ghi
	    [1] => jkl
	)

    [2] => Array
	(
	    [0] => mno
	    [1] => pql
	)

    [3] => Array
	(
	    [0] => abc
	    [1] => def
	)

    [4] => Array
	(
	    [0] => ghi
	    [1] => jkl
	)

    [5] => Array
	(
	    [0] => mno
	    [1] => pql
	)

)

 

//remove duplicateds from the array
 $uniqueIdsQtys = array();
     foreach($arrayIdsQtys2 as $val) {
         $uniqueIdsQtys[$val['id']] = $val;
     }

 //check the output
var_dump($uniqueIdsQtys);

 

Categorized in: