I try to replace some value in a multidimensional array with another array with the same key but it turns out to replace all values
Here is my example array
[
{
"book_id": 45,
"language_code": "RUWT-EN",
"book_name": Study,
"country": "Singapore",
"created_by": 12,
"created_date": "2019-04-09 09:19:24",
"update_by": 12,
"update_date": "2019-06-25 03:57:52",
"status": "1",
},
{
"book_id": 46,
"language_code": "RUWT-EN",
"book_name": Sleep,
"country": "Indonesia",
"created_by": 12,
"created_date": "2019-04-09 09:19:24",
"update_by": 12,
"update_date": "2019-06-25 03:57:52",
"status": "1",
},
{
"book_id": 47,
"language_code": "RUWT-EN",
"book_name": Teaching,
"country": "China",
"created_by": 12,
"created_date": "2019-04-09 09:19:24",
"update_by": 12,
"update_date": "2019-06-25 03:57:52",
"status": "1",
},
]
and this is my 2nd array
[
{
"book_id": 45,
"language_code": "RUWT-CH",
"book_name": Study in CH,
"country": "Korea",
"status": "2",
},
{
"book_id": 46,
"language_code": "RUWT-CH",
"book_name": Sleep in CH,
"country": "US",
"status": "2",
},
{
"book_id": 47,
"language_code": "RUWT-CH",
"book_name": Teaching in CH,
"country": "England",
"status": "2",
},
]
I've tried using laravel map collection and foreach one by one values then replace the value that have the same key, but it was to long . i want easiest way
$result = $collect_real->map(function($item) use($lang){
return $item['book_name'] = $lang->where('book_id', $item['book_id'])->values();
});
i want result like this
[
{
"book_id": 45,
"language_code": "RUWT-CH",
"book_name": Study in CH,
"country": "Korea",
"created_by": 12,
"created_date": "2019-04-09 09:19:24",
"update_by": 12,
"update_date": "2019-06-25 03:57:52",
"status": "2",
},
{
"book_id": 46,
"language_code": "RUWT-CH",
"book_name": Sleep in CH,
"country": "US",
"created_by": 12,
"created_date": "2019-04-09 09:19:24",
"update_by": 12,
"update_date": "2019-06-25 03:57:52",
"status": "2",
},
{
"book_id": 47,
"language_code": "RUWT-CH",
"book_name": Teaching in CH,
"country": "England",
"created_by": 12,
"created_date": "2019-04-09 09:19:24",
"update_by": 12,
"update_date": "2019-06-25 03:57:52",
"status": "2",
},
]