Check if there are array values ​​set by PHP

Possible duplicate:
check if the array has one or more empty values

What is the best / easiest way to check if an array has any values? I myself installed the keys, no matter what, I can not go on the keys. My code will show what I'm doing and want to do:

$array = array( "Birthday" => $row3['birthday'], "Sex" => $row3['sex'], "Lives In" => $row3['livesIn'] ); if(empty($array)) { foreach($array as $key => $value) { if($value) { echo "<tr><td>".$key."</td><td>".$value."</td></tr>"; } } } else { echo "This user has not provided any information yet"; } 

So, for example, if $row3['birthday'] , $row3['sex'] , $row3['livesIn'] all empty, then it should make the first if statement false and go to the else statement.

+4
source share
1 answer

I believe that you are looking for array_filter() , which with one parameter will remove all array values ​​that are false when typecasted to boolean:

 if( count( array_filter( $array)) == 0) { echo "Array contained 'empty' values\n"; } 

You can review the manual to see which values ​​will become logical false .

+10
source

Source: https://habr.com/ru/post/1444403/


All Articles