ltpitt
asked on
Merge arrays in PHP based on keys
I have this array:
And this array:
I would like to merge the "mesi_pagati" only to its relative id_decoder.
How can I obtain that in php?
Maybe part of the problem is that the second array is made by two arrays.
I obtain this with this code:
But I can change it to numeric or to anything else if helps obtain the final result of a single array with all needed data.
Array
(
[0] => Array
(
[id_decoder] => 1
[id_cliente] => 1
[id_gruppo] => 2
[decoder] => decoder1
[username] => decoder1
[password] => decoder1
[note] => decoder1
[nome] => primo
[cognome] => primini
[nome_gruppo] => mascia
)
[1] => Array
(
[id_decoder] => 2
[id_cliente] => 2
[id_gruppo] => 1
[decoder] => decoder2
[username] => decoder2
[password] => decoder2
[note] => decoder2
[nome] => secondo
[cognome] => secondini
[nome_gruppo] => miei
)
[2] => Array
(
[id_decoder] => 3
[id_cliente] => 3
[id_gruppo] => 2
[decoder] => decoder3
[username] => decoder3
[password] => decoder3
[note] => decoder3
[nome] => Terzo
[cognome] => Terzini
[nome_gruppo] => mascia
)
)
And this array:
Array
(
[id_decoder] => 1
[mesi_pagati] => 2
)
Array
(
[id_decoder] => 2
[mesi_pagati] => 1
)
I would like to merge the "mesi_pagati" only to its relative id_decoder.
How can I obtain that in php?
Maybe part of the problem is that the second array is made by two arrays.
I obtain this with this code:
$row = $result->fetch_array(MYSQLI_ASSOC);
But I can change it to numeric or to anything else if helps obtain the final result of a single array with all needed data.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The key is to practice and look at other code.
There is only so much you can get out of a book - if you have the basics the rest is about application.
Thanks for the points - and you are most welcome
There is only so much you can get out of a book - if you have the basics the rest is about application.
Thanks for the points - and you are most welcome
Some good learning resources are identified in this article.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
The Welling-Thompson book might be perfect!
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
The Welling-Thompson book might be perfect!
ASKER
Can I ask you something really important for me?
Where can I learn to handle arrays like that?
I am doing code school and code academy but exercises are basic on arrays and on for loops.
I am missing something that allows me to be that great.
Thanks a ton for the perfect solution.