I would like to join two arrays in PHP, the same as I could do with MySQL join left
. I have two arrays:
$db_products
from database (it hasid
andsku
fields)$csv_prices
from a CSV file (it hassku
andprice
fields)
$db_products
: (it has 4000 items)
Array
(
[0] => Array
(
[id] => 1012
[sku] => asd123
)
[N] => Array
(
[id] => ...
[sku] => ...
)
)
$csv_prices
: (it has 8000 items)
Array
(
[0] => Array
(
[sku] => asd123
[price] => 15.50
)
[N] => Array
(
[sku] => ...
[price] => ...
)
)
The join is $db_products[$key][sku] = $csv_prices[$key][sku]
. To find the matching pair, I am doing loops in loops which result in 4000 * 8000 check for match. It consumes a lot of energy and time, and I want to be more efficient.
I could lower by 10% the used time, by unset()
-ing the used $csv_prices[$key]
, but I want to be more efficient.