Tuesday, 17 September 2013

replace value in multi dimensional array with another value in PHP

replace value in multi dimensional array with another value in PHP

In PHP, I have an array as follows:
array(35) {
[0] => array(11) {
'dept_number' → str•4 '2310'
'dept_descr' → str•10 'Some Stuff'
}
[1] => array(11) {
'dept_number' → str•4 '1010'
'dept_descr' → str•11 'Other Stuff'
}
...and so on
I have another array as follows:
array(22) {
[2310] => str•6 'Bakery'
[1010] => str•4 'Beer'
...and so on
I want to replace the dept_descr in the first array with the description
in the second array, where the dept_number in the first array matches the
key in the second array. so, the result would be:
array(35) {
[0] => array(11) {
'dept_number' → str•4 '2310'
'dept_descr' → str•6 'Bakery'
}
[1] => array(11) {
'dept_number' → str•4 '1010'
'dept_descr' → str•4 'Beer'
}
How is this done?

No comments:

Post a Comment