我知道在php中字符串是......的,但是例如我可以这样做:
为什么我可以像在数组中一样遍历它们,但不能用count计数?(我知道可以使用strlen())
$str = 'String';
echo $str[0];
echo $str[1];
//result
S
t
echo count($str)
//result
1
为什么我可以像在数组中一样遍历它们,但不能用count计数?(我知道可以使用strlen())
[]
对字符串进行索引是语法糖。在PHP中,字符串不是数组。 - Tomalak