PHP version of truth table for expressions-TrueValueTable, truth table logical expression_PHP tutorial

WBOY
Release: 2016-07-13 10:05:32
Original
1022 people have browsed it

PHP version of truth table for expressions-TrueValueTable, truth table logical expression

PHP version of truth table for expressions-TrueValueTable, truth table logical expression_PHP tutorialphp error_reporting(E_ALL & ~E_NOTICE); $expression=$_GET['TrueTable']; //Read input box data if(!empty($_GET['TrueTable'])){ $expression=strtoupper($expression); //Replace the entered lowercase letters with uppercase letters Letter $expressionArr=str_split($expression); //Convert $expression into array foreach($expressionArr as $v){ //Put letters in $varTotal in array if($v>='A' && $v<='Z'){ $varTotal[]=$v; } } $varTotal = array_unique($varTotal); //Remove repeated letters in the $varTotal array sort($varTotal); //Forward sorting of letters in the $varTotal array $varTotal1 = preg_replace("/([A-Z])/","$\1",$varTotal); //The letters in the $varTotal1 array become variables $maxN = count($varTotal); //$expressionArr = preg_replace("/([A-Z])/","$\1",$expressionArr); //The letters in the $expressionArr array become variables $newExpression=implode('',$expressionArr); //$expressionArr array becomes a string //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); //Convert $expression into array $expressionArr = preg_replace("/([A-Z])/","$\1",$expressionArr); $newExpression=implode('',$expressionArr); //echo $newExpression; } ?> Truth table query 1.0 BY:Xiao Zhen $_GET['TrueTable'] ?>"/>

[Explanation: disjunction (|), conjunction (&), non-(!), implication (->), equivalence (=) ]

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]."

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/963545.htmlTechArticlephp版的求表达式的真值表-TrueValueTable,真值表逻辑表达式 ? php error_reporting ( E_ALL ~ E_NOTICE ); $expression = $_GET ['TrueTable']; // 读取输入框数据...
Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!