I have two array $softwarelist
and $virt_software_select
when i use @foreach
in blade template like below code i got checked but $softwarelist
is double in label.
$softwarelist =["Adobe Photoshop","Adobe Illustrator","Corel Draw","My SQL","Oracle"];
$virt_software_select=["Adobe Photoshop","My SQL"];
@foreach($softwarelist as $slst)
@foreach($virt_software_select as $sw_usr)
@if($slst->software==$sw_usr->virtualize_software)
<label>
<input type="checkbox" checked name="virt_software[]" value="{{$slst->software}}"/>
{{$slst->software}}
</label>
@else
<label>
<input type="checkbox" name="virt_software[]" value="{{$slst->software}}"/>
{{$slst->software}}
</label>
@endif
@endforeach
@endforeach
How can i get checked the same data in two array but not double data with $softwarelist
in laravel?
2
Answers
You have to use in_array() php function then it will work and use only one foreach
Hope it helps!
You have to use in_array() function instead of using nested foreach