etrader Posted April 18, 2011 Share Posted April 18, 2011 I have two array, how I can have if else to check if both array1 and array2 are empty? if (empty both arrays) { } else { even if one of them are not empty } Quote Link to comment https://forums.phpfreaks.com/topic/234025-how-to-check-if-two-arrays-are-empty/ Share on other sites More sharing options...
AtomicRax Posted April 18, 2011 Share Posted April 18, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234025-how-to-check-if-two-arrays-are-empty/#findComment-1202844 Share on other sites More sharing options...
ignace Posted April 18, 2011 Share Posted April 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234025-how-to-check-if-two-arrays-are-empty/#findComment-1202904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.