Re: A little confusing thing on (mistakenly) geting a offset from string with multi dim index.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



\R\N wrote:

> I'm not a experter of PHP and I even need other people's help to read PHP 
> source code, but in the information from the document and the talking with 
> other people gives me some guts to guess the $string['check'][0] actually 
> will be converted into $string[(int)'check'][0] and then into $string[0][0], 
> so the test 1 can be pass. Is that right?

Yes.

> So, what I want to know is, why there has two kind of behaviour for isset? 
> Maybe it's better to let the isset($string['check'][0]) and 
> isset($string['check']) both return false?

The behavior of isset is fine.  Consider that $string['check'] is
treated as $string[0], so it evaluates to a string with only the first
character of $string.  Then it is checked, whether this string has a
character at position zero.  As this is true, isset returns true.

You may consider using array_key_exists() instead of isset().

-- 
Christoph M. Becker

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux