Re: Ensuring that variable contains a number

From: Date: Sat, 09 Dec 2006 23:54:37 +0000
Subject: Re: Ensuring that variable contains a number
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-245679@lists.php.net to get a copy of this message
On 10/12/06, Richard Lynch <ceo@l-i-e.com> 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

« previous php.general (#245679) next »