jwhite68 Posted July 20, 2007 Share Posted July 20, 2007 I have an array: $errs = array(); And in the code, I want to check if the array has any values assigned to its elements. e.g. if $errs[1] or $errs[2] have been set to values then its not empty. But if no elements (ie no keys) have been assigned to the array, how can I easily check for this? I think I have been through the various array functions in PHP and couldnt see anything obvious. Link to comment https://forums.phpfreaks.com/topic/60926-how-to-check-array-is-empty/ Share on other sites More sharing options...
Daniel0 Posted July 20, 2007 Share Posted July 20, 2007 if(count($array) > 0) { echo "is not empty"; } else { echo "is empty"; } Link to comment https://forums.phpfreaks.com/topic/60926-how-to-check-array-is-empty/#findComment-303167 Share on other sites More sharing options...
clearstatcache Posted July 20, 2007 Share Posted July 20, 2007 u may also used if(empty($array)) { print "array is empty"; } Link to comment https://forums.phpfreaks.com/topic/60926-how-to-check-array-is-empty/#findComment-303177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.