我有一个数组
Array
(
[0] => Canon ProII PE-1000GC (MBL), Metallic Blue Electric Guitar
[1] => Captain Tsubasa DVD Box
[2] => Canon EOS Kiss X4 (550D / Rebel T2i) + Double Zoom Lens Kit
[3] => Fresh Chiba Roasted Seaweed
)如果我试图找到canon,我的预期结果如下
Array
(
[0] => Canon ProII PE-1000GC (MBL), Metallic Blue Electric Guitar
[1] => Canon EOS Kiss X4 (550D / Rebel T2i) + Double Zoom Lens Kit
)如何找到这个数组并将其存储到花药变量中。请引导我。
发布于 2013-08-13 14:51:44
循环遍历这些值,并使用strpos()搜索单词Canon的值。
foreach ($data as $value) {
if (strpos($value, 'Canon') !== false) { //if string contains 'Canon'
$newArray[] = $value; //store it into a new array
}
}
print_r($newArray);产出:
Array
(
[0] => Canon ProII PE-1000GC (MBL), Metallic Blue Electric Guitar
[1] => Canon EOS Kiss X4 (550D / Rebel T2i) + Double Zoom Lens Kit
)Working demo!
https://stackoverflow.com/questions/18212265
复制相似问题