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

Sakibbs's avatar

Array in checkbox not working

i want to show checkbox item to check when someone want to edit. i tried it but failed. In the below i gave a code.

@php $data = User::find($id); $a= explode(',', $data->infomaiton); @endphp

<input type="checkbox" class="new-control-input" name="abc[]" value="bcg" @if(in_array($a, ['bcg'])) checked @endif> BCG

when i dd($a) in found this array in my view.

array:3 [ 0 => "bcg" 1 => "polio" 2 => "tt" ]

0 likes
9 replies
awsqed's avatar

Can you provide an example of $data->b? I think the problem is the in_array().

Sakibbs's avatar

when i dd($a) in found this array in my view.

array:3 [ 0 => "bcg" 1 => "polio" 2 => "tt" ]

Sakibbs's avatar

when i dd($a) in found this array in my view.

array:3 [ 0 => "bcg" 1 => "polio" 2 => "tt" ]

Please or to participate in this conversation.