开发者

All numbers that are NOT in an array under 1000

开发者 https://www.devze.com 2023-02-05 14:21 出处:网络
I\'ve got this programming problem. I have number for example 1000. Now I have a number in an array, like 999.

I've got this programming problem.

I have number for example 1000.

Now I have a number in an array, like 999.

Now I need to display all numbers that are NOT in the array but are 1 开发者_如何学Goto 1000;

The next requirement is essential: It has to be displayed in a way that it's easy to oversee.

So I was thinking, lets show:

100
200
300
400
500
600
700
800
900
910
920
930
940
950
960
970
980
990
991
992
993
994
995
996
997
998
1000

What is the best way to start programming this?


<?php

$in_array = array (999);
$flipped = array_flip($in_array);
for ($i = 1; $i < 1000; $i++)
{
    if (!isset($flipped[$i]))
    {
         $out_array[] = $i;
    }
}
echo implode(" ", $out_array);


$myArray = array(999);
$notInArray = array_diff(range(1,1000),$myArray);
echo implode("\n", $notInArray);
0

精彩评论

暂无评论...
验证码 换一张
取 消