Php 从range()函数中排除数字
我正在用20到60的数字动态填充一个选择框 使用范围(20,60) 我需要用20到60的数字填充选择框,不包括数组中的数字:25、30、31、50 您可以使用Php 从range()函数中排除数字,php,arrays,numbers,range,Php,Arrays,Numbers,Range,我正在用20到60的数字动态填充一个选择框 使用范围(20,60) 我需要用20到60的数字填充选择框,不包括数组中的数字:25、30、31、50 您可以使用功能: <?php $range = range(20, 60); $a = array(25, 30 , 31, 50); // the array_diff() function returns the values in the "$range" array // that are not present in the arr
功能:
<?php
$range = range(20, 60);
$a = array(25, 30 , 31, 50);
// the array_diff() function returns the values in the "$range" array
// that are not present in the array of "$a".
$allRanges = array_diff($range, $a);
foreach ($allRanges as $range) {
echo '<option value="'.$range.'">'.$range.'</option>';
}
?>
如果($range==25)/*例如*/{///什么都不做}其他{///做任何事}
。或者更好的如果(在数组中($range,$a))…
尝试:-
输出:-http://prntscr.com/7cm5q6
$a = array(25, 30 , 31, 50);
<?php
$range = range(20, 60);
$a = array(25, 30 , 31, 50);
// the array_diff() function returns the values in the "$range" array
// that are not present in the array of "$a".
$allRanges = array_diff($range, $a);
foreach ($allRanges as $range) {
echo '<option value="'.$range.'">'.$range.'</option>';
}
?>