Home  >  Article  >  Backend Development  >  PHP function to delete the same elements in an array_PHP tutorial

PHP function to delete the same elements in an array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:40:54857browse

  1. // Delete the same elements in the array and keep only one same element
  2. function formatArray($array)
  3. {
  4. sort($array);
  5. $tem = ;
  6. $temarray = array();
  7. $j = 0;
  8. for($i=0;$i
  9. {
  10. if($array[$i]!=$tem)
  11.                                                                                       tem = $ array[$i];
  12. }
  13. return $temarray;
  14. }
  15. //Test calling function
  16. $array = array(aa,bb,aa,3,4,5,5,5,5,bc);
  17. $arr = formatArray($array);
  18. print_r($arr);
  19. ?>
  20. I hope the above example can be helpful to everyone.
http://www.bkjia.com/PHPjc/486182.html

www.bkjia.com
true

http: //www.bkjia.com/PHPjc/486182.html

? // Delete the same elements in the array and keep only one same element function formatArray($array) { sort($ array); $tem = ; $temarray = array(); $j = 0; for($i=0;$icount($array);$i ) { if...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn