How do I remove an item from an array that has a key but the value is blank?

    Assuming you know the key, [man]unset/man would still work. Of course, you could search for NULL and then remove the element whose value is NULL.

      I don't really know the key. I could probably find it but I'd hate to add a whole level of complexity to this procedure.

        never mind... I just thought of something. I really should not have blank values in this field. I'd just have to go into my db and fix it.

          Oh, an idea involving [man]array_filter/man comes to mind:

          <?php
          $array = array(1, 2, 3, NULL, 4, 5, NULL, 6, 7, 8);
          print_r($array);
          
          echo "<br />\n";
          
          $array = array_filter($array, create_function('$value', 'return $value !== NULL;'));
          print_r($array);
          ?>

          EDIT:

          I really should not have blank values in this field. I'd just have to go into my db and fix it.

          Yes, that would be even better.

            Write a Reply...