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

vandan's avatar
Level 13

how to check multiple array elements using in_array()

hii guys

i try to check my multiple array value check if condition but doesnt work

here is my code

@if(in_array(['payment','userprofile','complains'],explode(',',$users->enable_feature)))    
    ...............
@elseif(array_intersect('userprofile', explode(',', $users->enable_feature)))
    .................
#else
    ...............
@endif

here is my code single value perfect work but i try to multple value check then return else part how to do it any other function or may be this function

0 likes
4 replies
sujancse's avatar

you just swapped in_array and array_intersect

Simply array_intersect will work.

array_intersect(['payment','userprofile','complains'],explode(',',$users->enable_feature))
@if(array_intersect(['payment','userprofile','complains'],explode(',',$users->enable_feature)))    
    .................
#else
    ...............
@endif
1 like
vandan's avatar
Level 13

@sujancse

when i check using array_intersect always return if condition

like my value "userprofile" then return if condition

@if(array_intersect(['payment','userprofile','complains'],explode(',',$users->enable_feature)))    
        ...............
@elseif(array_intersect('userprofile', explode(',', $users->enable_feature)))
        .................
@else
        ...............
@endif

how to check particular value wise condition

sujancse's avatar

Flip it like

@if(in_array('userprofile', explode(',', $users->enable_feature)))    
        ...............
@elseif(array_intersect(['payment','userprofile','complains'],explode(',',$users->enable_feature)))
        .................
@else
        ...............
@endif 
vandan's avatar
Level 13

@sujancse but this is not right way

for example

@if(in_array('userprofile', explode(',', $users->enable_feature)))    
        ...............
@elseif(array_intersect(['payment','complains'],explode(',',$users->enable_feature)))
    ................
@elseif(array_intersect(['payment','userprofile','complains'],explode(',',$users->enable_feature)))
        .................
@else
        ...............
@endif 

so now how can i do it?

Please or to participate in this conversation.