0
我知道有array_intersect
php
但我想要显示像两个数组中的元素。 例如:Php匹配2个数组之间的值,但敌人像元素
array1 = [product, php]
array2 = [product management, html]
我想要的结果数组以显示result = [product managemenet]
array_intersect将在这里给空的结果。
我知道有array_intersect
php
但我想要显示像两个数组中的元素。 例如:Php匹配2个数组之间的值,但敌人像元素
array1 = [product, php]
array2 = [product management, html]
我想要的结果数组以显示result = [product managemenet]
array_intersect将在这里给空的结果。
$result=array();
$array1 = array('product','php');
$array2 = array('product management','html');
$srcharray = $array2;
foreach($array1 as $serchstr)
{
foreach($srcharray as $key => $serchval)
{
if (strpos($serchval, $serchstr) !== false) {
$result[] = $serchval;
unset($srcharray[$key]);
}
}
}
var_dump($result);
注:如果您需要区分大小写的匹配项,请使用'stripos'而不是'strpos'。
你是不是想让两张桌子相交呢? – PacMan
类型的交集,但如果数组1中的任何元素被发现为数组2中的一部分,它将需要显示,就像我提到的,如果数组1有一个元素产品和数组2有一个元素产品管理结果应显示产品管理 –