format your code please
Mar 15, 2021
9
Level 1
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" ]
Level 3
Yeah you got the in_array() wrong. It should be in_array('bcg', $a): https://www.php.net/manual/en/function.in-array.php
Please or to participate in this conversation.