php-在数组中搜索字符串
但是得到同样的结果-我对php是新手,如果这很容易的话,我很抱歉 任何帮助都将不胜感激php-在数组中搜索字符串,php,arrays,Php,Arrays,但是得到同样的结果-我对php是新手,如果这很容易的话,我很抱歉 任何帮助都将不胜感激 干杯似乎$selectedTags是一个字符串数组,因为您的foreach只循环一次 你应该试着去做 if (in_array($tagToFind, $selectedTags, true)) { // search the array for $tagToFind - true = strict echo ' Found'; } else { echo ' Not found'; }
干杯似乎$selectedTags是一个字符串数组,因为您的
foreach
只循环一次
你应该试着去做
if (in_array($tagToFind, $selectedTags, true)) { // search the array for $tagToFind - true = strict
echo ' Found';
} else {
echo ' Not found';
}
然后在数组中使用
函数似乎$selectedTags是一个字符串数组,因为您的foreach
只循环一次
$selectedTags = explode(" ",$page->getAttribute($tags->getAttributeKeyHandle()));
你应该试着去做
if (in_array($tagToFind, $selectedTags, true)) { // search the array for $tagToFind - true = strict
echo ' Found';
} else {
echo ' Not found';
}
然后在数组中使用
函数
$selectedTags = explode(" ",$page->getAttribute($tags->getAttributeKeyHandle()));
似乎返回了一个字符串
那么
$page->getAttribute($tags->getAttributeKeyHandle())
没有意义-您得到一个包含一个长字符串的数组
您想要的是:
$selectedTags=$page->getAttribute($tags->getAttributeKeyHandle())
似乎返回了一个字符串
那么
$page->getAttribute($tags->getAttributeKeyHandle())
没有意义-您得到一个包含一个长字符串的数组
您想要的是:
$selectedTags=$page->getAttribute($tags->getAttributeKeyHandle())
那最好用
if(stristr($selectedTags, $tagToFind)){
// do something
}
else{
// do something else
}
希望这对你有用,然后更好地使用
if(stristr($selectedTags, $tagToFind)){
// do something
}
else{
// do something else
}
愿这对你有用太棒了-只要你知道怎么做就容易了!太棒了-当你知道怎么做的时候,很容易!