Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-在数组中搜索字符串_Php_Arrays - Fatal编程技术网

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'; }

但是得到同样的结果-我对php是新手,如果这很容易的话,我很抱歉

任何帮助都将不胜感激


干杯

似乎$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
}

愿这对你有用

太棒了-只要你知道怎么做就容易了!太棒了-当你知道怎么做的时候,很容易!