Remove duplicate values from an array php
Posted by Raj
How can remove duplicate values from an array php
array_unique :Removes duplicate values from an array
Syntax:
array_unique(array,sort flag);
sort flag:
ORT_REGULAR - compare items normally
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
SORT_LOCALE_STRING - compare items as strings, based on the current locale.
Example:
<?php
$arr = array("php","tutorial","php","example");
$unique_arr = array_unique($arr); //removes duplicate values from an array
print_r($unique_arr );
?>
Outputs:
Array
(
[0] => php
[1] => tutorial
[2] => example
)
array_unique :Removes duplicate values from an array
Syntax:
array_unique(array,sort flag);
sort flag:
ORT_REGULAR - compare items normally
SORT_NUMERIC - compare items numerically
SORT_STRING - compare items as strings
SORT_LOCALE_STRING - compare items as strings, based on the current locale.
Example:
<?php
$arr = array("php","tutorial","php","example");
$unique_arr = array_unique($arr); //removes duplicate values from an array
print_r($unique_arr );
?>
Outputs:
Array
(
[0] => php
[1] => tutorial
[2] => example
)
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
delete duplicate values,
deleting duplicates,
PHP,
PHP interview questions and answers,
remove duplicate records,
remove duplicate values
.You can leave a response, or trackback from your own site.