【发布时间】:2022-01-30 18:59:38
【问题描述】:
我试图从包含单词DEVICE 的数组中过滤字符串。
我使用了以下技术来检查数组中是否有一个名为“拥有设备”的单词,但它会打印出来
未找到匹配项
即使有包含单词 DEVICE 的字符串。
这是我尝试过的尝试:
$output= array('football GAME', 'cricket GAME', 'computer DEVICE','mobile DEVICE');
$string = 'DEVICE';
foreach ($output as $out) {
if (strpos($string, $out) !== FALSE) {
echo "Match found";
return true;
}
}
echo "Match Not found!";
return false;
所需输出:
输出应该是:
找到匹配项。
我还想显示由单词DEVICE 组成的项目列表,例如:
computer DEVICE
mobile DEVICE
我需要在这里进行什么更正?
【问题讨论】:
-
您的
strpos参数从后到前。这是strpos(string $haystack, string $needle)