Level 73
What about putting this in a collection and pluck the recipe_id out of it?
$result = collect($data)->pluck('recipe_id');
$data should be the result that you showed above.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How to extract items from this kind of array? I want array to be like [ 1, 2, 2, 3]. No matter what I do, can't get something like that.
array:4 [▼
0 => {#305 ▼
+"recipe_id": 1
}
1 => {#303 ▼
+"recipe_id": 2
}
2 => {#310 ▼
+"recipe_id": 2
}
3 => {#309 ▼
+"recipe_id": 3
}
]
What about putting this in a collection and pluck the recipe_id out of it?
$result = collect($data)->pluck('recipe_id');
$data should be the result that you showed above.
Please or to participate in this conversation.