I have a form input and if script receive word tip (see if statement), it echo "do this" This work good
Now I want to echo another word based on previous word "do this" with if statement, but this not work
$at=(stripos($a, 'tip') === 0);
if ($at == true) {echo "do this";}
if (echoword == do this) {echo "do that";}
you cant not rely on "previous echo" just rely on condition like this:
$at=(stripos($a, 'tip') === 0);
if ($at == true) {
echo "do this";
echo "do that";
}
becaus in this case your "previous echo" depends only on that condition
IF - is a basic control structure. http://php.net/manual/en/control-structures.elseif.php
I believe you want to do it like this
$at=(stripos($a, 'tip') === 0);
if ($at == true) {
$echoword="do this";
echo $echoword;
}
if (isset($echoword) && $echoword == 'do this'){
echo "do that";
}
Which one you prefer?
1. Put your code in existence if
statement.
$at=(stripos($a, 'tip') === 0);
if ($at == true) {echo "do this"; echo "do that";}
2. Use $at
whenever you want to write related thing.
$at=(stripos($a, 'tip') === 0);
if ($at == true) {echo "do this";}
if ($at) {echo "do that";}
3. Store the echoed word in variable
$at=(stripos($a, 'tip') === 0);
$echoed = '';
if ($at == true) {echo "do this"; $echoed = "do this";}
if ($echode == "do this") {echo "do that";}