【问题标题】:How string can be removed recurring characters and only stay unique chars in Php? [duplicate]如何删除字符串中重复出现的字符并只在 Php 中保留唯一字符? [复制]
【发布时间】:2017-03-24 12:11:56
【问题描述】:

如何去除字符串中重复出现的字符,只保留 PHP 中的唯一字符? 例如:这是字符串xsxssssdddxxxs 我需要的结果应该是xsd

【问题讨论】:

    标签: php string char unique repeat


    【解决方案1】:

    也许是这样,

    $str = 'aassdd';
    echo implode('',array_unique(str_split($str, 1)));
    

    【讨论】:

      【解决方案2】:

      你可以这样做:

      $str = "my string that contains multiple same charactersasldjasj";
      echo implode('',array_unique(str_split($str, 1)));
      

      【讨论】:

        猜你喜欢
        • 2022-01-18
        • 2011-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多