RE: [PHP] A little confusing thing on (mistakenly) geting a offset from string with multi dim index.
| From: | Ford, Mike | Date: | Thu, 15 May 2014 16:26:42 +0000 |
| Subject: | RE: [PHP] A little confusing thing on (mistakenly) geting a offset from string with multi dim index. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323331@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jim Lucas [mailto:lists@cmsws.com]
> Sent: 15 May 2014 16:47
> To: php-general@lists.php.net
> Subject: Re: [PHP] A little confusing thing on (mistakenly) geting a
> offset from string with multi dim index.
>
> On 05/14/2014 05:55 PM, Rain Lee wrote:
> > So, here is the TLDR;
> >
> > $string = 'this is a string';
> >
> > In PHP 5.5
> > isset($string['check']) === false
> > isset($string['check'][0]) === true
> >
> > Why can't let
> > isset($string['check']) === false
> > isset($string['check'][0]) === false <--
> >
> > ?
> >
>
> I can see WHAT you are doing and WHAT the results are, but I don't
> understand
> WHY would you ever do this?
>
> You defined $string with a string of characters. But you are trying
> to use
> $string as an array. This hits me as completely wrong.
That's a perfectly normal PHP idiom to get the nth character of the
string, I do it all over the place - $string[$n] is equivalent to
substr($string, $n, 1);
Cheers!
Mike
--
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
403a Leslie Silver Building, City Campus, Leeds Metropolitan University,
Woodhouse Lane, LEEDS, LS1 3ES, United Kingdom
E: m.ford@leedsmet.ac.uk T: +44 113 812 4730
From 22 September 2014 Leeds Metropolitan University will become Leeds Beckett University.
Find out more at http://www.leedsbeckett.ac.uk
To view the terms under which this email is distributed, please go to:-
http://www.leedsmet.ac.uk/email-disclaimer.htm