i have an array full of objects , in each object there is properties i wanna collect a specific property in all the object that i have and assign them to a variable.
this is the array
[
{
"id": 23,
"user_id": 2,
"friend_id": 2,
"created_at": "2018-05-23 21:00:07",
"updated_at": "2018-05-23 21:00:07"
},
{
"id": 31,
"user_id": 2,
"friend_id": 1,
"created_at": "2018-05-23 21:00:07",
"updated_at": "2018-05-23 21:00:07"
},
{
"id": 32,
"user_id": 2,
"friend_id": 4,
"created_at": "2018-05-23 21:00:07",
"updated_at": "2018-05-23 21:00:07"
}
]
i wanna get the value of friend_id
whats the best practices to do so? thanks.
array_column($your_array, 'friend_id')json_decode()to create associative arrays instead of objects.