douyan2970 2014-04-24 04:56
浏览 34
已采纳

在特定位置包含1或0的集合中搜索二进制数

I have an array of strings (zeros and ones) in a format similar to the following:

[01100101],[10010000],[00000001]...and so on (all the same length, there's about 30 entries)

I'd like to be able to search these numbers using a search similar to "0xxxx01". The search, in this case, would return the first and third string.

What would be the best way to go about doing this? I'm in the middle of learning PHP, an answer in that format would be preferred.

  • 写回答

3条回答 默认 最新

  • dongwen3093 2014-04-24 07:06
    关注

    Building on top of the answer posted by @George Lund (you need to use . instead of X):

    $arr = array('01100101','10010000','00000001');
    
    $result = preg_grep("/0.....01/", $arr);
    
    print_r($result);
    

    Demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥40 微信小程序 使用vant组件ActionSheet 下拉面板,内容区域滚动会触发。scroll-view自定义下拉刷!即使设置停止下拉刷新也不行。
  • ¥15 专业问题提问,7月5号2点之前
  • ¥25 使用cube ai 导入onnx模型时报错
  • ¥15 关于#微信小程序#的问题:用一个网页显示所有关联的微信小程序数据,包括每个小程序的用户访问量
  • ¥15 root的安卓12系统上,如何使apk获得root或者高级别的系统权限?
  • ¥20 关于#matlab#的问题:如果用MATLAB函数delayseq可以对分数延时,但是延时后波形较原波形有幅度上的改变
  • ¥15 使用华为ENSP软件模拟实现该实验拓扑
  • ¥15 通过程序读取主板上报税口的数据
  • ¥15 matlab修改为并行
  • ¥15 尝试访问%1服务的windows注册表时遇到问题。必须先解决此问题,然后才能运行安装过程。(请确认您正在使用管理员权限运行)373