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 } 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 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. 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
Archived
This topic is now archived and is closed to further replies.