Reply to Re: '0' passed to function treated as 'null'

Your name:

Reply:


Posted by My Pet Programmer on 12/28/07 17:32

rynato said:
> I have a lengthy 'markup.php' file which consists of functions which
> take as input the various attribute values of HTML tags and spit out
> the HTML tag. My problem is that the function for <input> is
> interpreting '0' as null and because I've written the functions so
> that they don't write out the attributes which have null value, it
> doesn't generate a 'value="0"' attribute for <input>.
>
> Simplified example:
>
> function input($value=null) {
>
> $input = '<input';
> if ($value)
> $input .= ' value="' . $value . '"';
> else
> if ($type == 'checkbox' || $type == 'radio')
> echo('you must specify a value for the attribute "value" of
> <input>');
> $input .= ' />';
> return $input;
> }
>
> So... my question is, how - when passing the argument '0' for $value -
> do I make PHP understand that 0 is not null, and so it should go ahead
> and write 'value="0"' instead of throwing my error msg?
>
> thx in adv
if ($value || $value == 0)

~A!

--
Anthony Levensalor
anthony@mypetprogrammer.com

Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. - Albert Einstein

[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

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