check if an array have one or more empty values

后端 未结 5 2285
无人共我
无人共我 2021-02-19 11:34

I have the array $var, and I\'d like to return FALSE if one or more element in the array are empty (I mean, the string are \"\").

I think that array_filter()

5条回答
  •  猫巷女王i
    2021-02-19 12:25

    function emptyElementExists()

    function emptyElementExists($arr) {
      return array_search("", $arr) !== false;
      }
    

    Example:

    $var = array( "text1", "", "text3" );
    var_dump( emptyElementExists($var) );
    

    Output:

    bool(true)

    Reference

    • array_search()

提交回复
热议问题