Hello,
I've wrote an algorithm to check 2 arrays (A & 😎, if there is same element in both of them, this element goes to 3rd array (C).
I know there is PHP function like array_intersect, but I've to write algorithm.
My code:
<?php
$A = Array('Joe', 'Bob', 'Sarah', 'Bill', 'Suzy');
$B = Array('Joe', 'pos', 'suzy', 'Bob');
$lenghtA = count($A);
$lenghtB = count($B);
for ($i=0; $i <= $lengthA; $i++)
{
if ($A[i] == $B[i]) $C[] = $A[i];
$i++;
for ($j=0; $j <= $lengthB; $j++)
{
if ($A[j] == $B[j]) $C[] = $A[j];
$j++;
}
}
print_r($A);
echo ("<br>");
print_r($B);
echo ("<br>");
print_r($C);
?>
I hope everything is OK with algorithm, but my array C (3rd) is kinda empty.
Pleas help!