[PHP-users 4477] Re: 文字列-> 配列

WADA Hiroyuki php-users@php.gr.jp
Wed, 26 Dec 2001 16:26:45 +0900


Osamu Shigematsu wrote:

> <?php
> $a = '123';
> $j = strlen($a);
> for($i=0;$i<=$j;++$i){
>     print ord($a[$i]) ."\n";
> }

> 今まで知りませんでしたが、C と同じようにかけるのでものすごく楽です。

マニュアルに書いてありますが、[]でなく{}を使う方がいいです。

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 the array-braces.
However, this syntax is deprecated as of PHP 4.