Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to put each element of array into another array in same order

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

>Solution :

Loop over one of the arrays, using the indexes to access the corresponding element in the other array.

foreach ($first_array AS $i => $value) {
    $second_array[$i]['value'] = $value;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading