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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.