Re: Accessing a Char in an Array
| From: | Curt Zirzow | Date: | Tue, 21 Dec 2004 03:27:16 +0000 |
| Subject: | Re: Accessing a Char in an Array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204925@lists.php.net to get a copy of this message | ||
* Thus wrote Justin Palmer:
> In an earlier thread labeled "first letter", it was suggested that
> substr() be used.
Just for the record the usage of
$str = 'a string';
$str[0];
Is strongly discouraged, it is recommended to use:
$str{0};
See Section (String access and modification by character):
http://php.net/language.types.string
>
> >Check this out...
> >http://us2.php.net/manual/en/function.substr.php.
>
> So my question is:
>
> What is faster using substr or accessing the string like an array?
>
> I know I could test this myself, but I thought someone may have done
> this already.
Speed is probably negligible. It probably comes down to readablity.
Curt
--
Quoth the Raven, "Nevermore."