Question

After I use array_unique() on an array, when I var_dump() the array, it still has the same content, with duplicates:

array(21) { 
[0]=> string(10) "tricou_CRS" 
[1]=> string(10) "tricou_CRM" 
[2]=> string(11) "tricou_CRXL" 
[3]=> string(10) "tricou_CBM" 
[4]=> string(10) "tricou_CBL" 
[5]=> string(10) "tricou_CWS" 
[6]=> string(11) "tricou_CWXL" 
[7]=> string(10) "tricou_CRS" 
[8]=> string(10) "tricou_CRM" 
[9]=> string(11) "tricou_CRXL" 
[10]=> string(10) "tricou_CBM" 
[11]=> string(10) "tricou_CBL" 
[12]=> string(10) "tricou_CWS" 
[13]=> string(11) "tricou_CWXL" 
[14]=> string(10) "tricou_CRS" 
[15]=> string(10) "tricou_CRM" 
[16]=> string(11) "tricou_CRXL" 
[17]=> string(10) "tricou_CBM" 
[18]=> string(10) "tricou_CBL" 
[19]=> string(10) "tricou_CWS" 
[20]=> string(11) "tricou_CWXL" }

Which obviously has some duplicates. Now, there's not much code that could help, really, because it's just

array_unique($myarr);
var_dump($myarr);

So, what am I missing there? Shouldn't array_unique() remove the duplicates? Both the type and the content is the same in many of the array's positions.

Was it helpful?

Solution

$uniquearr = array_unique($myarr);
var_dump($uniquearr);

Always read docs first

array_unique

Return Values

Returns the filtered array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top