The consensus seems to be that the proposed "ifset()" and "ifempty()"
functions are more effort than they are worth. What I'd like to know
is, why "empty()" still exists when every time I turn around, the
mentors I turn to locally tell me not to use it, to use "isset()"
instead. Because empty() doesn't work with zero. Anyone care to take
a stab at that?


They serve different purposes and both work very well.

$form_errors = array();

// process form
foreach (array('name', 'email') as $field) {
  # Hey! someone hacked the form! This field is supposed to be there!
  if (!isset($_POST[$field])) {
    $form_errors[] = 'Field ' . $field . ' was missing';
    continue;
  }

  # The field is there but has no value.
  if (empty($_POST[$field])) {
    $form_errors[] = 'Field ' . $field . ' was empty';
  }
}

if (!empty($form_errors)) {
  echo 'there were errors in processing the form.<br/>';
  exit;
}

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to