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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация