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

Vishaal's avatar

Checkbox array saved in database

Hello,

I have an checkbox multiple option saved in mine database.

User1: Sample checkbox value; EXP1,EXP2,EXP3,

User2: Sample checkbox value; EXP1,EXP2,EXP4,

Is it possible to get the userid which is member of Sample checkbox value: EX3 ?

Database is:

ID, UserID, Checkbox value

I'm building this in Laravel 5.8

0 likes
4 replies
Snapey's avatar

if you have literally just put the string "EXP1,EXP2,EXP3" into a database column then you need to use

 ->where('CheckboxValue', 'like', '%EXP3%')->get();
Vishaal's avatar

@SNAPEY - Thank you this works.

How i can search in array?

Sample; EXP3 and EXP4?

Snapey's avatar

You cannot easily unless you can guarantee the order of the parameters,

eg

->where('CheckboxValue', 'like', '%EXP3%EXP4%')->get();

To create the search string from an array;

$term = '%' . implode('%',$expArray) . '%';

Note that this creates an AND statement, but this will not find EXP4,EXP2,EXP3

This is one reason it is better to have these in a separate table with a pivot

Please or to participate in this conversation.