dsmvqp3124 2019-04-09 08: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 08: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条)
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部