foreach ($items as &$item) {
$item['stocks'] = array_values(array_filter(
$item['stocks'],
fn($el) => $el['type'] === 'fbs'
));
}
$stocks = [
'stocks' => [] // в массиве $stocks создаем один элемент
];
foreach ($items as $itemIndex=>$item) {
foreach($item['stocks'] as $stockIndex=>$stock) {
if ($stock['type'] === "fbo") {
unset($items[$itemIndex]['stocks'][$stockIndex]);
}
}
}
foreach ($items as &$item) {
$item['stocks'] = array_values(array_filter(
$item['stocks'],
fn($el) => $el['type'] === 'fbs'
));
}
print_r($items);
$stocks = [
'stocks' => [] // в массиве $stocks создаем один элемент
];
foreach ($items as $itemIndex=>$item) {
foreach($item['stocks'] as $stockIndex=>$stock) {
if ($stock['type'] === "fbo") {
unset($items[$itemIndex]['stocks'][$stockIndex]);
}
}
}
foreach ($items as $k => $v) {
$stocks['stocks'][] = [
'offer_id' => $v['offer_id'],
'stock' => $v['stocks'][key($v['stocks'])]['present'],
'warehouse_id' => '2222',
];
}
print_r($stocks);
Array ( [stocks] => Array ( [0] => Array ( [offer_id] => AR-001 [stock] => 50 [warehouse_id] => 2222 )[1] => Array ( [offer_id] => AR-002 [stock] => 0 [warehouse_id] => 2222 ) ) )
$stocks = [
'stocks' => [] // в массиве $stocks создаем один элемент
];
foreach ($items as $itemIndex=>$item) {
foreach($item['stocks'] as $stockIndex=>$stock) {
if ($stock['type'] === "fbo") {
unset($items[$itemIndex]['stocks'][$stockIndex]);
}
}
$stocks['stocks'][] = [
'offer_id' => $item['offer_id'],
'stock' => $item['stocks'][1]['present'],
'warehouse_id' => '2222',
];
}
print_r($stocks);
Array ( [stocks] => Array ( [0] => Array ( [offer_id] => AR-001 [stock] => 50 [warehouse_id] => 2222 )[1] => Array ( [offer_id] => AR-002 [stock] => 0 [warehouse_id] => 2222 ) ) )
$stocks = [
'stocks' => [] // в массиве $stocks создаем один элемент
];
foreach ($items as $itemIndex=>$item) {
foreach($item['stocks'] as $stockIndex=>$stock) {
if ($stock['type'] === "fbo") {
unset($items[$itemIndex]['stocks'][$stockIndex]);
}
}
$stocks['stocks'][] = [
'offer_id' => $item['offer_id'],
'stock' => $item['stocks'][1]['present'],
'warehouse_id' => '2222',
];
}
print_r($stocks);