|
Posted by Kimmo Laine on 08/01/05 06:40
"Michael G" <mike-g@montana.com> kirjoitti
viestissδ:42ed93bc$1_2@spool9-west.superfeed.net...
> Hi,
>
> $PHONETIC is an array of strings. How can !$PHONETIC['d'], in the case
> below, evalutae to true. It is a string not a boolean. It would make more
> sense if it evalutated to null.
>
> Thanks Mike
>
> <?php
>
> $PHONETIC = array('a' => 'alpha', 'b' => 'bravo', 'c' => 'charlie');
>
> if(!$PHONETIC['d']):
> echo 'true';
> else:
> echo 'false';
> endif
>
> ?>
Why would it be a string? It is un undefined variable (undefined array
indexs to be precise). If you call it with a boolean operator, bolean is
assumed, just as well false is assumed since it had no value before. !false
evaluates true quite logically.
$PHONETIC is not an array of strings by no definition. Sure, it contains
three variables that happen to be strings, but that still doesn't meka any
difference. It is simply an array that can hold any kinds of variable types.
There are other tests, that you might find useful. isset() tells you wether
a variable (or array reference) is defined or not. gettype() tells yuo what
is the type of the given variable.
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Soulman <eternal.erectionN0@5P4Mgmail.com>
Navigation:
[Reply to this message]
|