I am using array_unique to get rid of the duplicate values in an array. But, the problem is array_unique does not consider data types while checking for duplicates. For example:
$a = [1, true, null, false];
$u = array_unique($a);
var_dump($u);
Outputs:
array(2) {
[0] =>int(1)
[2] =>NULL
}
But, if you consider data types every value of the array are unique. I know I can fix this by running a loop. But, is there a better way or an alternative to array_unique by which I can achieve this?
(string) $elem1 === (string) $elem2. It's intended for strings and numbers, not arbitrary types.