Kod
Array
(
[rozmiary] => Array
(
[0] => Array
(
[nazwa] => XS
[cena] => 1
)
[1] => Array
(
[nazwa] => S
[cena] => 2
)
[2] => Array
(
[nazwa] => M
[cena] => 3
)
[itd...]
)
[szczegoly] => Array
(
[XS] => Array
(
[nazwa_rozmiaru] => XS
[width] => 100
[height] => 100
)
[S] => Array
(
[nazwa_rozmiaru] => S
[width] => 200
[height] => 200
)
[M] => Array (
[nazwa_rozmiaru] => M
[width] => 300
[height] => 300
)
)
)
(
[rozmiary] => Array
(
[0] => Array
(
[nazwa] => XS
[cena] => 1
)
[1] => Array
(
[nazwa] => S
[cena] => 2
)
[2] => Array
(
[nazwa] => M
[cena] => 3
)
[itd...]
)
[szczegoly] => Array
(
[XS] => Array
(
[nazwa_rozmiaru] => XS
[width] => 100
[height] => 100
)
[S] => Array
(
[nazwa_rozmiaru] => S
[width] => 200
[height] => 200
)
[M] => Array (
[nazwa_rozmiaru] => M
[width] => 300
[height] => 300
)
)
)
I chciałbym z tego uzyskać tablice takiej postaci i później (lub wcześniej jeszcze przed połączeniem tablic, nie wiem jak będzie wygodniej) usunąć z niej wszystkie tablice gdzie wartość 'nazwa' jest inna niż 'S' albo 'M' (różnych rozmiarów może być oczywiście więcej niż na przykładzie, mnie interesuje zostawienie tylko wybranych 2-3):
Kod
Array
(
[0] => Array
(
[nazwa] => XS
[cena] => 1
[width] => 100
[height] => 100
)
[1] => Array
(
[nazwa] => S
[cena] => 2
[width] => 200
[height] => 200
)
[2] => Array
(
[nazwa] => M
[cena] => 3
[width] => 300
[height] => 300
)
[3] => Array
(
[nazwa] => L
[cena] => 4
[width] => 400
[height] => 400
)
[itd...]
)
(
[0] => Array
(
[nazwa] => XS
[cena] => 1
[width] => 100
[height] => 100
)
[1] => Array
(
[nazwa] => S
[cena] => 2
[width] => 200
[height] => 200
)
[2] => Array
(
[nazwa] => M
[cena] => 3
[width] => 300
[height] => 300
)
[3] => Array
(
[nazwa] => L
[cena] => 4
[width] => 400
[height] => 400
)
[itd...]
)
Próbowałem to osiągnąć za pomocą foreach:
foreach ($tablica['rozmiary'] as $v1 => $v2) { foreach ($tablica['szczegoly'] as $v3 => $v4) { $wynik[] = array ('name' => $v2['nazwa'], 'price' => $v2['cena'], 'width' => $v4['width'], 'height' => $v4['height']); } }
oraz dwóch osobnych foreach łączonych za pomocą array_merge, ale to nadal nie jest to czego mi trzeba, nie wspominając już o późniejszym usuwaniu (chociaż tutaj myślałem o zastosowaniu array_intersect). Proszę bardziej o sugestie jakimi funkcjami powinienem się zainteresować i jak powinienem spróbować ugryźć ten problem zamiast o gotowe rozwiązania
