Home > Backend Development > PHP Tutorial > 一个数组值空缺的计算,该如何解决

一个数组值空缺的计算,该如何解决

WBOY
Release: 2016-06-13 10:25:15
Original
749 people have browsed it

一个数组值空缺的计算
假如数组值为
$a=array('1','8','2','3','11');
要计算出11以下那些4,5,6,7,9,10还没有存在于该数组怎么计算?

因为这个数组的最大值11可能是任意数,所以要根据最大值来确定比他小的值还有那些没有在该数组中。。。。

------解决方案--------------------

PHP code
$a=array('1','8','2','3','11');$b = range($a[0], $a[count($a) - 1]);$result = array_diff($b, $a); //缺少的值,即$b与$a的差集print_r($result);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template