Jump to content

How to check if two arrays are empty


etrader

Recommended Posts

if ($array1 == '' && $array2 == '') {
//both are empty
} else {
//one has a value
}

 

is a simple value check, but something like

 

if (count($array1) == '0' && count($array2) == '0') {
//both are empty
} else {
//one has a value
}

 

might help too? depends

if(empty($a1) && empty($a2)) {

 

$array1 == '' doesn't work with array's and count($array1) == '0' should be count($array1) == 0 since count() returns an integer, which wins, and the string constant '0' is converted to 0 therefor it's better to write:

 

count($a1) == 0

 

You'll avoid needless conversions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.