|
Posted by John Murtari on 10/02/07 17:07
lawrence k <lkrubner@geocities.com> writes:
> I've got a function that starts off like this:
>
> function alphabeticalListOfAlbumsByLetter($whichLetter="a") {
>
> }
>
>
> I pass in the letters (a, b, c, d, etc) and the numbers (0, 1, 2, 3,
> 4, etc). It finds in the database records starting with that letter or
> number. It works fine except when I try to pass in a zero. The PHP
> code acts as if I have not passed in a function argument, so
> $whichLetter becomes "a", which is the default value (as you can
> see).
>
> So how do I get PHP to see that I'm really passing in a zero, and not
> just some false value?
THere are a few ways to do this, you may want to try the
REALLY EQUAL operator, "===". An example:
function isItZero($x) {
if ($x) {
echo "non zero param $x\n";
} else if (!$x && $x === 0) {
echo "int zero $x\n";
} else if (!$x && $x === '0') {
echo "char zero $x\n";
} else {
echo "Blank param\n";
}
}
isItZero('a');
isItZero("");
isItZero(0);
isItZero('0');
---- WILL OUTPUT
non zero param a
Blank param
int zero 0
char zero 0
--
John
___________________________________________________________________
John Murtari Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211) "TheBook.Com" (TM)
http://thebook.com/
Navigation:
[Reply to this message]
|