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

From: Date: Tue, 13 May 2014 17:56:34 +0000
Subject: Re: A little confusing thing on (mistakenly) geting a offset from string with multi dim index.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-323298@lists.php.net to get a copy of this message
\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

« previous php.general (#323298) next »