Массив-один (массив базы данных продукта):
- Идентификатор продукта
- Имя кошки
- Идентификатор кошки
- Имя кошки
Код: Выделить всё
//this foreach is loop to products
foreach($objects as $object) {
//get cat name from product db
$cat_name_product = $object['values']['17'];
// this foreach is loop to cat db
foreach($cat_db as $cat_object) {
// get cat name from cat db
$cat_name_cat_table = $cat_object['values'][2];
// if cat from product DB is equal to cat name from cat DB
if($cat_name_product == $cat_name_cat_table){
$cat_name_product_id = $object['id'];
$cat_name_db_id = $cat_object['id'];
// Add products ids to a specfic row id from cat
$cat_db_row[$cat_name_db_id][] = $cat_name_product_id;
}
}
}
Код: Выделить всё
Array
(
[45156381272] => Array
(
[0] => 44990952854
)
[45002415686] => Array
(
[0] => 45054787942
[1] => 45056971448
[2] => 45049917079
[3] => 45056971449
)
)
Код: Выделить всё
Array
(
[0] => (
[cat_id] => 45156381272
[product_ids] => Array
(
[0] => 44990952854
)
)
[1] =>
[cat_id] => 45156381272
[product_ids] => Array
(
[0] => 45054787942
[1] => 45056971448
[2] => 45049917079
[3] => 45056971449
)
)
Подробнее здесь: https://stackoverflow.com/questions/671 ... -array-php