dpxkkhu1812 2016-12-28 07:32
浏览 67
已采纳

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

Let's say I have input string

String 1 : 1234123
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

String 1 : array(4)
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-28 07:39
    关注

    Boring solution but it works!

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法