Re: Ensuring that variable contains a number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/12/06, Richard Lynch <ceo@xxxxxxxxx> wrote:
My take:

$number = (int) $number;
if ($number < 1) $number = 1;

You could error out for < 1, or compare the original with the (int)
cast  to see if PHP considers them = and error out if not, while using
the (int) cast to be SURE you have an int, or...

But a typecast and inequality test should be pretty clear and cheap.


Hey, nice. Thanks!

Dotan Cohen

http://what-is-what.com/what_is/bluetooth.html
http://lyricslist.com/lyrics/artist_albums/509/whitesnake.php

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux