Jesper Brunholm wrote in <3DF5A2C6.4020102@brunholm-scharff.dk>:
> $str = 'Morten';
> print $str[0];
> Vil resultere i et 'M'.
> 1) Jeg mener at kunne huske at det faktisk er en forkert brug (men kan
> ikke lige finde referencen i manualen)?
String access by character
Characters within strings may be accessed by specifying the zero-based
offset of the desired character after the string in curly braces.
Note: For backwards compatibility, you can still use array-braces for the
same purpose. However, this syntax is deprecated as of PHP 4.
-
http://www.php.net/manual/en/language.types.string.php
> 2) er substr() ikke mindst lige så god og effektiv?
> (<
www.php.net/substr/>)
Tjah, vurder selv:
$forbogstav = $str{0};
$forbogstav = substr($str, 0);
Substr() kan mere, men hvis man ikke har brug for det, så er det andet
nemmere, synes jeg i hvert fald.
--
Mvh.
Niels Andersen
(la nels. anersyn.)