ある配列を別の配列と比較しようとしています。
$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] に従ってグループ化されます。そのため、製品のグループと直送 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 関数が必要ですか?