Home >php教程 >php手册 >php版的求表达式的真值表-TrueValueTable,真值表逻辑表达式

php版的求表达式的真值表-TrueValueTable,真值表逻辑表达式

WBOY
WBOYOriginal
2016-06-13 09:13:42976browse

php版的求表达式的真值表-TrueValueTable,真值表逻辑表达式

php error_reporting(E_ALL & ~E_NOTICE); $expression=$_GET['TrueTable']; //读取输入框数据 if(!empty($_GET['TrueTable'])){ $expression=strtoupper($expression); //将输入的小写字母,替代成大写字母 $expressionArr=str_split($expression); //将$expression转换成数组 foreach($expressionArr as $v){ //把字母放在 $varTotal数组中 if($v>='A' && $v){ $varTotal[]=$v; } } $varTotal = array_unique($varTotal); //去掉$varTotal数组中重复的字母 sort($varTotal); //$varTotal数组中字母正向排序 $varTotal1 = preg_replace("/([A-Z])/","$\\1",$varTotal); //$varTotal1数组中字母变成变量 $maxN = count($varTotal); //$expressionArr = preg_replace("/([A-Z])/","$\\1",$expressionArr); //$expressionArr数组中字母变成变量 $newExpression=implode('',$expressionArr); //$expressionArr数组变成字符串 //echo $newExpression."
";
$newExpression= preg_replace("/([A-Z])->([A-Z])/","!\\1|\\2",$newExpression); $newExpression= preg_replace("/(\(.*?\))->([A-Z])/","!\\1|\\2",$newExpression); $newExpression= preg_replace("/(\(.*?\))->(.*?)/","!\\1|\\2",$newExpression); $newExpression= preg_replace("/([A-Z])->(.*?)/","!\\1|\\2",$newExpression); $expressionArr=str_split($newExpression); //将$expression转换成数组 $expressionArr = preg_replace("/([A-Z])/","$\\1",$expressionArr); $newExpression=implode('',$expressionArr); //echo $newExpression; } ?>

真值表查询1.0 BY:小臻 $_GET['TrueTable'] ?>"/>

[ 说明:析取(|) , 合取(&) , 非(!) , 蕴含(->) , 等价(=) ]

php echo ""; if(!empty($_GET['TrueTable'])){ foreach($varTotalas$v){ echo ""; } echo ""; $result=pow(2,$maxN); for($i=0;$i$result;$i++){ $resultN[$i]=sprintf("%0{$maxN}d",decbin($i)); $resultN[$i]=str_split($resultN[$i]); } foreach($resultNas$k=>$v){ echo ""; foreach($resultN[$k] as$k1=>$v1){ echo ""; $varTotal2[$k1]=$varTotal1[$k1]."=".$v1; //echo $varTotal2[$k1]." ";eval($varTotal2[$k1].";"); } //echo $newExpression;eval("\$varTotal3[] = ".$newExpression.";"); foreach($varTotal3as$k2=>$v){ if($v==NULL){ $varTotal3[$k2]=0; } } echo ""; echo ""; } //print_r($varTotal3); } ?>
{$v}结果
".$v1." ".$varTotal3[$k]."
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn