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

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

WBOY
WBOY원래의
2016-06-13 09:13:42976검색

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]."
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.