dsmvqp3124 2019-04-09 16:50
浏览 44
已采纳

在php中检查收到的索引继承

I'am searching the best way to do that test in php : So i have a list which contains numbers and I have to check the succesion of these numbers so if there is no succession it is necessary to announce an alert and to recover the missing index or the list of the missing indexes

So for example my array is like that:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 6 [5] => 9 )

Here my algorithm must returns missing indexes are : [5,7,8]

  • 写回答

2条回答 默认 最新

  • douyinzha5820 2019-04-09 16:55
    关注

    If you make a range of the min and max value then use array_diff that should give you the result you want.

    $arr = []; // your array
    $range = range(min($arr), max($arr));
    var_export(array_diff($range, $arr));
    // [5,7,8]
    

    https://3v4l.org/0pE3o

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

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持