Answer the question
In order to leave comments, you need to log in
Is there a function in php or laravel to compare names in arrays?
There are 2 associative arrays:
$arr1[] = [
'name1' => 'Имя',
'name2' => 'Имя2'
];
$arr2[] = [
'name1' => 'Имя2',
'name2' => 'Имя4',
'link' => 'href'
];
Answer the question
In order to leave comments, you need to log in
<?php
$arr1 = [
'name1' => 'Имя',
'name2' => 'Имя2'
];
$arr2 = [
'name1' => 'Имя2',
'name2' => 'Имя4',
'link' => 'href'
];
function array_cross(&$arr1,&$arr2,$r=false) {
foreach($arr1 as $k1=>$a1) {
$f=false;
foreach($arr2 as $k2=>$a2)
if($a1==$a2) {$f=true;break;}
if(!$f) unset($arr1[$k1]);
}
if(!$r) array_cross($arr2,$arr1,true);
}
array_cross($arr1,$arr2);
echo '$arr1[] = ';
print_r($arr1);
echo '<br>$arr2[] = ';
print_r($arr2);
/*
$arr1[] = Array ( [name2] => Имя2 )
$arr2[] = Array ( [name1] => Имя2 )
*/
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question