我有一个类似
的数组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
)
如何找到并将此数组存储到其他变量中。请指导我。
答案 0 :(得分:0)
循环显示值并使用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
)