Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

inovador's avatar

Array inside IN () raw Query

I'm working on a project, which has a gigantic raw query with a concatenated query like this: column in(".$filters."))

I need maintain the raw query, but use bind parameters to pass an array.

Does anyone how to pass array in this situation?

0 likes
1 reply
click's avatar

As far as I know you have to create the ?, ?, ?, ?.. manually in this case if you use raw queries.

$yourData = ['a','b','c'];

// creates ?,?,?
$questionMarks = trim(str_repeat('?,', count($yourData)), ',');

->whereRaw("
    something = something_else
    column in ({$questionmarks})
", $yourData);

If you don't want to or can't use the ? parameter and need named parameters you could loop over your data and create a string like :val_1, :val_2, :val_3 and than pass your values as [`val_1' => 'a', 'val_2' => 'b', 'val_3' => 'c'];

1 like

Please or to participate in this conversation.