Reply to Re: strange outcome when comparing int value against a give minimum and maximum value

Your name:

Reply:


Posted by Steve on 02/12/07 21:10

| function checkInteger(&$value, $checks) {
| $err = '';
| if (!is_numeric($value) || (floatval($value) != intval($value))) {
| $err .= 'Input must be an integer. ';
| } else {
| $value = intval($value);
| if ($checks['MinValue'] != '' && $value <
| intval($checks['MinValue'])) {
| $err .= 'Minimum value = ' . $checks['MinValue'] . '. ';
| }
| if ($checks['MaxValue'] != '' && $value >
| intval($checks['MaxValue'])) {
| $err .= 'Maximum value = ' . $checks['MaxValue'] . '. ';
| }
| }
| }


function checkInt($value, $min, $max)
{
if (!is_numeric($value)){ return false; }
if (floatval($value) != intval($value)){ return false; }
}

don't use magic variables like $checks. either make legit params like
$min/$max or make $checks an object. as it is, you don't even check to see
if $checks is an array. further, don't live in nests. if there are
conditions that must be met before your code should run, then begin by
dropping out of the function *at the first possible opportunity* ... that
keeps the code not only neater but definitively shows what the conditions
are.

as for why your code didn't work before...well, you have to show us what the
code *was* before. most likely, you didn't cast correctly.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация