2

我有一个像

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      
)

我怎样才能找到这个数组并将其存储到另一个变量中。请指导我。

4

1 回答 1

0

循环遍历这些值并使用strpos()来搜索 word 的值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
)

工作演示!

于 2013-08-13T14:51:44.347 回答