I have first array:
Array
(
[0] => generala value 1
[1] => specificatii value 1
)
and second array is:
Array
(
[0] => Array
(
[title] => generala title 1
[atribute_cat_id] => 1
[product_id] => 98
)
[1] => Array
(
[title] => specificatii title 1
[atribute_cat_id] => 2
[product_id] => 98
)
)
I want to get this array form:
Array
(
[0] => Array
(
[title] => generala title 1
[atribute_cat_id] => 1
[product_id] => 98
[value] => generala value 1
)
[1] => Array
(
[title] => specificatii title 1
[atribute_cat_id] => 2
[product_id] => 98
[value] => specificatii value 1
)
)
I tried with array_merge but this method put all elements from first array to each element from second array!
Every time both arrays have same number of elements!
Any ideea?
Thank you!
4
Answers
Like below you can do
A simple iterative loop is probably the easiest to follow. However, if you’re looking for something more compact then this might suit:
Loop over one of the arrays, using the indexes to access the corresponding element in the other array.
You can do this using a
foreach
loop. Keep it simple. 🙂If you prefer the destructive approach: