I have two huge arrays:
- array A has 4900 items (each item is a small array)
- array B has 700 items (also each item is a small array)
So basically thees are my arrays:
A = array (
[0] => array(
"name" => "KE-KE IMPEX ",
"email" => "someemai@gmail.com",
"kezbCompany" => "Fragrance",
"startDate" => "2013-03-25 00:00:00",
"endDate" => "2014-03-25 00:00:00",
"companyBase" => "06 20 232 2534"
)
...
[4900] => array(
"name" => "Jane Doe",
"email" => "zzer@sad.com",
"kezbCompany" => "sadsad",
"startDate" => "2013-03-25 00:00:00",
"endDate" => "2014-03-25 00:00:00",
"companyBase" => "06 20 232 2534"
)
)
B = array (
[0] => array(
"name" => "KE-KE IMPEX 46554 sda",
"email" => "xxx@gmail.com",
"kezbCompany" => "546wer",
"startDate" => "2013-03-25 00:00:00",
"endDate" => "2014-03-25 00:00:00",
"companyBase" => "06 20 232 2534"
)
...
[700] => array(
"name" => "45 Jane Doe",
"email" => "kekeimpex@gmail.com",
"kezbCompany" => "asd",
"startDate" => "2013-03-25 00:00:00"
)
)
The small items look like this for example (booth in A and in B):
array(
'name' => 'John Doe',
'email' => 'john@doe.com'
)
So what I need to do is: check which small array has the same name.
But please keep in mind that most of the time the two small arrays wont be the same in structure.
So for example maybe their email are different. Right now, if I loop through the A first and inside that I loop through the B it takes a whole lot of time.
This is my current code:
$szData = file_get_contents('szData.txt');
$kData = file_get_contents('kData.txt');
$A = json_decode($szData);
$B = json_decode($kData);
$foundNr = 0;
foreach ($A as $key => $sz)
{
$cName = $sz->companyName;
foreach ($B as $index => $k)
{
$pattern = '/^(.*)+('.$cName.')/i';
echo "SzSor: " . $key . " --- Ksor: " . $index . "</br>";
if (preg_match($pattern, $k->companyName))
{
$founData[] = $k->companyName;
++$foundNr;
}
}
}
Any ideas?