How to remove duplicate values from an array in PHP?

Posted by Prem Tiwari | Updated on

If you to remove duplicate values from an array in PHP? Use array_unique() to remove duplicate values from an array.

Parameter details

ParameterDescription
arrayRequired. Specifying an array
sorttypeOptional. Specifies how to compare the array elements/items. Possible values:

  • SORT_STRING – Default. Compare items as strings
  • SORT_REGULAR – Compare items normally (don’t change types)
  • SORT_NUMERIC – Compare items numerically
  • SORT_LOCALE_STRING – Compare items as strings, based on current locale

PHP array_unique() function example


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers