How to remove duplicate values from an array in PHP

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

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

24条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 04:08

    I have done this without using any function.

    $arr = array("1", "2", "3", "4", "5", "4", "2", "1");
    
    $len = count($arr);
    for ($i = 0; $i < $len; $i++) {
      $temp = $arr[$i];
      $j = $i;
      for ($k = 0; $k < $len; $k++) {
        if ($k != $j) {
          if ($temp == $arr[$k]) {
            echo $temp."
    "; $arr[$k]=" "; } } } } for ($i = 0; $i < $len; $i++) { echo $arr[$i] . "

    "; }

提交回复
热议问题