Level 102
$ids = $query->pluck('id_obrasca_prethodne');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using a raw SQL query that selects some ids from database. It looks like this:
$query = DB::select('SELECT pr.id_obrasca_prethodne
FROM public."prethodneNacionalneProcjene" AS pr
JOIN public."obrasciProcjeneVrste" AS ob ON pr.id_obrasca = ob.id WHERE ob.status LIKE \'Prihvaćen\'');
If I output the $query variable now, I get:
[{"id_obrasca_prethodne":8},{"id_obrasca_prethodne":28}]
I need to convert the result of query to PHP array so it contains only numbers (8, 28, ...). How can I do this?
then just add collect first
$ids = collect($query)->pluck('id_obrasca_prethodne');
Please or to participate in this conversation.