0

I want to check for some cases, but I can't get this to work.

$a and $b have values, but I have arrays like $c that I do not wish to print.

How to do this?

$a = array("1", "2", "3");
$b = array("A"); // array(1) { [0]=> string(5) "A" }
$c = array(""); // array(1) { [0]=> string(0) "" }

function does_have_value($arr) {
  if (!empty($arr)) {
   echo 'have value';
  }
}

does_have_value($a); // have value
does_have_value($b); // have value
does_have_value($c); // have value (but I want this to fail)
  • 1
    @u_mulder that doesn't answer my question, it's a special case, pleaaaaaaaaaaaaaaase stop closing my questions I've been fighting with this for over 2 hours now!!!!!!!!!!!! – babarosa83 Apr 21 '20 at 13:32
  • That's the second time this question has been closed with the same duplicate, but it doesn't answer the question. It's not about the array being empty, it's about the *values* being empty. Try https://stackoverflow.com/questions/5040811/checking-if-all-the-array-items-are-empty-php instead – iainn Apr 21 '20 at 13:33
  • @iainn in the first dupe there's a note "If you need to clean out empty values before checking..." so it could somehow help OP, but still I added your dupe too. – u_mulder Apr 21 '20 at 13:35
  • @iainn thanks, so you're saying that I have to do a loop and check if all items are empty? I thought there is a better solution than this, no? – babarosa83 Apr 21 '20 at 13:37
  • @u_mulder that note must have been added way after, I didn't even see a note for 2 min after closing.. can you paste it here please? – babarosa83 Apr 21 '20 at 13:39

0 Answers0