How to remove duplicate values from an array in PHP

后端 未结 24 1473
故里飘歌
故里飘歌 2020-11-22 03:40

How can I remove duplicate values from an array in PHP?

24条回答
  •  终归单人心
    2020-11-22 03:53

    That's a great way to do it. Might want to make sure its output is back an array again. Now you're only showing the last unique value.

    Try this:

    $arrDuplicate = array ("","",1,3,"",5);
    
    foreach (array_unique($arrDuplicate) as $v){
      if($v != "") { $arrRemoved[] = $v; }
    }
    print_r ($arrRemoved);
    

提交回复
热议问题