从阵列中的一个,如果...语句中使用条件值 [英] Using conditional values from an array in an if...statement

查看:108
本文介绍了从阵列中的一个,如果...语句中使用条件值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的条件数组:

$arrConditions = array ('>=2', '==1', '<=10');

...我希望能够在if ...语句中使用。

...which I want to be able to use in an if...statement.

IE浏览器。

if (5 $arrConditions[0])
{
  ...do something
}

...这将是相同的:

...which would be the same as :

if (5 >= 2)
{
  ...do something
}

任何帮助吗?

感谢

推荐答案

这个是什么?

<?php

$arrConditions = array('==2', '==9', '==5', '==1', '==10', '==6', '==7');

$count = 0;
$myval = 0;
foreach ($arrConditions as $cond) {
  $str = "if(5 $cond) { return  $count;}";
  $evalval = eval($str);
  if (!empty($evalval)) {
    $myval = $count;
  }
  $count++;
}

switch ($myval) {
  case 0: echo '==2 satisfied';
    break;
  case 1: echo '==9 satisfied';
    break;
  case 2: echo '==5 satisfied';
    break;
  case 3: echo '==1 satisfied';
    break;
  case 4: echo '==10 satisfied';
    break;
  default : echo 'No condition satisfied';
}
?> 

这篇关于从阵列中的一个,如果...语句中使用条件值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆