Strings as arrays in php

后端 未结 2 1762
粉色の甜心
粉色の甜心 2020-12-03 18:09

I know that strings in php are ..... strings but for example I can do

$str = \'String\';
echo $str[0];
echo $str[1];

//result
S
t

echo count($str)
//result         


        
2条回答
  •  萌比男神i
    2020-12-03 18:34

    Because that's how it works. You can access specific byte offsets using bracket notation. But that doesn't mean the string is an array and that you can use functions which expect arrays on it. $string[int] is syntactic sugar for substr($string, int, 1), nothing more, nothing less.

提交回复
热议问题