check associative array contains value

后端 未结 5 1711
粉色の甜心
粉色の甜心 2021-01-26 01:27
    Array (    
    [0] => Array ( 
               [questionID] => 47
               [surveyID] => 51
               [userID] => 31 
               [question         


        
5条回答
  •  星月不相逢
    2021-01-26 02:18

    This is probably the most hackish solution I'll come up with all this morning, but if you are shooting for a quick one-liner, this should do:

    if(in_array(1, array_column($myArray, 'required')))
       echo 'required';
    

    Edit: This assumes you've got PHP 5.5+ at hand

    Update: After a closer look at the documentation of in_array(), this should be possible:

    if(in_array(array('required' => 1), $myArray))
        echo 'required';
    

提交回复
热议问题