私は質問の助けが必要です、私はphpでコードを書く必要があります
数列の例、$ sequence = 3、5、9、11、13明らかに数7が欠落していますが、ループを使用すると仮定して、コードの実行方法がわかりませんが、開始するには、PHPである必要があります
シーケンスから欠落している番号を取得するためのより簡単な方法、私がそれを見る方法:
<?php
$sequence = array(3, 5, 9, 11, 13);
$numbers = array(7, 9, 15);
$single_nr = 7;
function getMissingNumber(array $sequence, $single_nr = null, $numbers = array())
{
// Check if it exists in the sequence array
// check single number
if($single_nr)
{
if(!in_array($single_nr, $sequence))
{
echo $single_nr . " is not in array" . "<br />";
}
}
// check an array of numbers
if($numbers)
{
foreach($numbers as $nr)
{
if(!in_array($nr, $sequence))
{
echo $nr . " is not in array" . "<br />";
}
}
}
}
echo getMissingNumber($sequence, null, $numbers);
?>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加