我正在尝试将一个数组与另一个数组进行比较。
$dropship_array = array();
$dropship_query = tep_db_query("select id, email from drop_shippers");
while ($dropship = tep_db_fetch_array($dropship_query)) {
$dropship_array[] = array('id' => $dropship['id'],
'email' => $dropship['email']);
}
现在, $dropship_array[] 包含:
Array (
[0] => Array (
[id] => 0
[email] => none
)
[1] => Array (
[id] => 2
[email] => dropshipper1@gmail.com
)
[2] => Array (
[id] => 5
[email] => dropshipper2@gmail.com
)
[2] => Array (
[id] => 10
[email] => dropshipper3@gmail.com
)
)
现在,我需要将上面的数组 (dropship_array['id']) 与下面的数组 (products_array['dsid']) 进行比较。products_array[] 数组已被拆分,以便每个单独的数组根据每个数组 [dsid] 组合在一起。因此,每次在一组产品和 drop ship id 之间找到匹配项时,都需要执行一个函数。
$products_array = array();
$products_query = tep_db_query("select products_id, products_name, drop_ship_id from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
$products_array[] = array('id' => $products['products_id'],
'text' => $products['products_name'],
'dsid' => $products['drop_ship_id']);
}
Array (
[0] => Array (
[0] => Array (
[id] => 793
[text] => Gun Dog Training Book
[dsid] => 8
)
)
[1] => Array (
[0] => Array (
[id] => 789
[text] => Top Dog II Training DVD Video
[dsid] => 5
)
[1] => Array (
[id] => 237
[text] => Tri-Tronics Retriever Training Book
[dsid] => 5
)
)
)
这需要一个 foreach 函数吗?