what code can i use to find this, if it is possible...
Code: Select all
<?php
$var="cheese";
$pancakerecipe="eggs,rice,cheese,corn";
if ( $var is in $pancakerecipe)
{
$boolean="true";
}
else
{
$boolean="false";
}
?>Moderator: General Moderators
Code: Select all
<?php
$var="cheese";
$pancakerecipe="eggs,rice,cheese,corn";
if ( $var is in $pancakerecipe)
{
$boolean="true";
}
else
{
$boolean="false";
}
?>Code: Select all
<?php
$var ="cheese";
$pancakerecipe = "Pancake Recipe
$pancakerecipe="eggs,rice,cheese,corn";
if ( $var is in $pancakerecipe)
{
print "$var is in the recipe for $pancakerecipe";
}
else
{
print ="$var is not in the recipe for $pancakerecipe";
}
?>Code: Select all
<?php
$var="cheese";
$pancakerecipe="eggs,rice,cheese,corn";
if (stristr($pancakerecipe, $var))
{
$boolean="true";
}
else
{
$boolean="false";
}
?>Code: Select all
<?php
$var = "Cheese";
$var = strtolower($var); //to be sure to catch that var even if its in caps
$pancakerecipe= array("eggs","rice","cheese","corn");
if ( in_array($var, $pancakerecipe) ) {
$boolean="true";
print "{$var} was found in the pancakerecipe";
}
else {
$boolean="false";
print "{$var} was NOT found in the pancakerecipe";
}
?>Code: Select all
<?php
function isRecipeItem($item, $recipe)
{
if (substr_count($item, $recipe) > 0)
{
return true; // don't quote if you want a boolean value rather than a string
}
else
{
return false;
}
}
// in use
if(isRecipeItem($item, $recipe) == true)
{
// do something
}
?>Code: Select all
$var='cheese';
$pancakerecipe='eggs,rice,cheese,corn';
if(in_array($var, explode(',', $pancakerecipe))){
...TRUE...
} else {
...FALSE...
}