简体   繁体   English

检查数组中的一个元素是否具有值

[英]check if one element in array has value

i have an array $error which tells me if any of my post vars produced an error or not: 我有一个数组$ error ,它告诉我我的任何var变量是否产生错误:

Array
(
    [pers_anrede] =>  1
    [pers_titel] => 1
    [pers_vorname] => 
    [pers_nachname] => 
    [pers_vorwahl] => 1 
    [pers_telefon] => 1
    [pers_email] => 
)

(where 1 means that the element has an error) (其中1表示元素有错误)

what is the most effective way to find out whether any errors at all are present? 找出是否存在任何错误的最有效方法是什么? if all elements in my array are set to 0, i want to continue doing something else. 如果我数组中的所有元素都设置为0,我想继续做其他事情。 if there is at least one error present, i want to display a general error message. 如果存在至少一个错误,我想显示一条常规错误消息。

if( in_array(1, $error) ) {
    //we have at least one error
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM