dpxkkhu1812 2016-12-27 23:32
浏览 67
已采纳

如何查找仅在字符串中出现一次的数字?

Let's say I have input string

  1. String 1 : 1234123
  2. String 2 : 76523752

From those string, I'd like to know which numbers that only appears once. So in my case the output should be

  1. String 1 : array(4)
  2. String 2 : array(6,3)

I'm guessing I'll use strpos() for this task but I couldn't get any logical flow to make this happen. Can you help me figure this out?

  • 写回答

3条回答 默认 最新

  • doulizhi1247 2016-12-27 23:39
    关注

    Boring solution but it works!

    1. $string="1234123";
    2. $result=array();
    3. foreach (count_chars($string, 1) as $i => $val) {
    4. if($val==1) $result[]=chr($i);
    5. }
    6. print_r($result);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部