简体   繁体   English

在 php 上的变量值上替换一个单词并在 elseif 语句中使用它

[英]replace a word on variable value on php and using it on elseif statements

If i have a variable like this on php :如果我在 php 上有这样的变量:

$codition = "question_1 == a AND question_2 == b";

is there any way to replace the value to be like this :有什么方法可以将值替换为这样的:

$codition = "$question_1 == 'a' && $question_2 == 'b'";

This variable I can use in this condition:我可以在这种情况下使用这个变量:

 if(echo $codition){
     echo "Success";
 } else {
     echo "fail";
 }

The reason I use a variable on condition (if else) because I have a rule in the database, and the value looks like the first value on the variable $codition , is it possible to replace a word on variable and using it on elseif statements?我使用条件变量(if else)的原因是因为我在数据库中有一个规则,并且该值看起来像变量$codition的第一个值,是否可以替换变量上的单词并在elseif语句中使用它?

I think you are off track entirely with your question.我认为你的问题完全偏离了轨道。 Below I attempt to get at your question, but making an educated guess at what you are asking.下面我试图回答你的问题,但对你在问什么做一个有根据的猜测。

Assume:认为:
Var $codition is a condition to check if 'a' or 'b' var $codition 是检查 'a' 或 'b' 的条件
Vars $q1codition and $q2codition are used to hold these strings 'a' and 'b'变量 $q1codition 和 $q2codition 用于保存这些字符串 'a' 和 'b'

Then:然后:

$q1codition = 'a';
$q2codition = 'b';

if($codition == $q1codition && $codition == $q2codition){
 echo "Success";
 } else {
 echo "fail";
 }

Is this what you are getting at?这是你的意思吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM