Checking if all the array items are empty PHP -
i'm adding array of items form , if of them empty, want perform validation , add error string. have:
$array = array( 'requestid' => '$_post["requestid"]', 'clientname' => '$_post["clientname"]', 'username' => '$_post["username"]', 'requestassignee' => '$_post["requestassignee"]', 'status' => '$_post["status"]', 'priority' => '$_post["priority"]' );
and if of array elements empty perform:
$error_str .= '<li>please enter value @ least 1 of fields regarding request searching for.</li>';
you can use built in array_filter
if no callback supplied, entries of input equal false (see converting boolean) removed.
so can in 1 simple line.
if(!array_filter($array)) { echo '<li>please enter value @ least 1 of fields regarding request searching for.</li>'; }
Comments
Post a Comment