You are here: Re: how control struct evaluate « PHP Programming Language « IT news, forums, messages
Re: how control struct evaluate

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° 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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация