Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP“;如果;在两个数字之间查找的语句_Php_If Statement - Fatal编程技术网

PHP“;如果;在两个数字之间查找的语句

PHP“;如果;在两个数字之间查找的语句,php,if-statement,Php,If Statement,我需要一个if语句的帮助,这里就是正在发生的事情 我有一个价值$paint['product_id'] 我需要说明,该值是否介于 81501-81599或 81701 - 81799 说废话 否则,如果该值介于 81001-81099或 81301 - 81399 说废话 否则如果 86501-86599或 86001-86099或 85001 - 85099 说废话 如果不适用,什么也别说 我试过什么 <? if ($paint['product_id'] >= 81501 &a

我需要一个if语句的帮助,这里就是正在发生的事情

我有一个价值$paint['product_id']

我需要说明,该值是否介于 81501-81599或 81701 - 81799 说废话

否则,如果该值介于 81001-81099或 81301 - 81399 说废话

否则如果 86501-86599或 86001-86099或 85001 - 85099 说废话

如果不适用,什么也别说

我试过什么

<? if ($paint['product_id'] >= 81501 && $x <= 81599 || $paint['product_id'] >= 81701 && $x <= 81799):?>
blah
<? elseif ($paint['product_id'] >= 81001 && $x <= 81099 || $paint['product_id'] >= 81301 && $x <= 81399):?>
blah2
<? elseif ($paint['product_id'] >= 86501 && $x <= 86599 || $paint['product_id'] >= 86001 && $x <= 86099 || $paint['product_id'] >= 85001 && $x <= 85099):?>
blah3
<? endif;?>

废话
废话
废话
我遇到的问题是“废话”出现在“废话”类别的物品上


希望这是有意义的,并提前感谢任何帮助

$x
替换为
$paint['product\u id']

您应该用括号将它们分组:

if( ($x > 10 && $x < 20) || ($x > 40 && $x < 50) ) { ...
if($x>10&&$x<20)| |($x>40&&$x<50)){。。。

您需要更多的括号

<?php
<? if (($paint['product_id'] >= 81501 && $x <= 81599) || ($paint['product_id'] >= 81701 && $x <= 81799)):?>
blah
<? elseif (($paint['product_id'] >= 81001 && $x <= 81099) || ($paint['product_id'] >= 81301 && $x <= 81399)):?>
blah2
<? elseif (($paint['product_id'] >= 86501 && $x <= 86599) || ($paint['product_id'] >= 86001 && $x <= 86099) || ($paint['product_id'] >= 85001 && $x <= 85099)):?>
blah3
<? endif;?>

废话
废话
废话

如果($paint['product_id']>=81501&&$x=81701&&&$x=81001&&$x=81301&&$x=86501&&&$x=86001&&$x=85001&$x至少有三种解决方法

用户已经发布了第一个解决方案

第二个解决方案是在函数之间创建并使用它

function between($number, $from, $to)
{
   return $number>$from && $number<$to;
}

  if(between($paint['product_id'], 81501, 81599) || $paint['product_id'], 81701, 81799))
   echo 'blah'; 
  else if(between($paint['product_id'], 81001, 81099) || $paint['product_id'], 81301, 81399))
   echo 'blah2';

  else if(between($paint['product_id'], 86501, 86599) || $paint['product_id'], 86001, 86099) || $paint['product_id'], 85001, 85099))
   echo 'blah3';
  else echo 'it does not apply';
介于($number,$from,$to)之间的函数
{

返回$number>from&&$number考虑创建一个用户定义的函数,例如

function between($x, $lim1, $lim2) {
  if ($lim1 < $lim2) {
    $lower = $lim1; $upper = $lim2;
  }
  else {
    $lower = $lim2; $upper = $lim1;
  }
  return (($x >= $lower) && ($x <= $upper));
}

如前所述,“中间”即使您事先不知道第一个参数还是第二个参数更大,函数也会工作。

这些范围是真实值吗?
是从哪里来的?我只是从网上找到了一些示例来尝试它们,$x没有任何意义,是的,这些是我需要的真实范围。如果您要指出这一点,您可能需要e确定你把它们都放在了正确的位置。在你写答案的同时,我在没有看到答案的情况下,创建了一个类似的
between
函数……请注意,OP使用的是
=
-范围包括端点。似乎就是这样,我的代码没有100%正确工作。
function between($x, $lim1, $lim2) {
  if ($lim1 < $lim2) {
    $lower = $lim1; $upper = $lim2;
  }
  else {
    $lower = $lim2; $upper = $lim1;
  }
  return (($x >= $lower) && ($x <= $upper));
}
if between($paint['product_id'], 81501, 81599) blah;