gpt4 book ai didi

PHP:字符串索引

转载 作者:IT王子 更新时间:2023-10-29 00:01:01 24 4
gpt4 key购买 nike

$str[n] 和 $str{n} 有什么区别,因为 $str 是一个字符串。

我注意到两者的工作方式似乎相同,除了我找到的任何文档中都没有出现 {}。

最佳答案

它们是一样的。但是,他们正在摆脱 {} 语法,因此您应该使用 []

According to the manual :

Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. The functions substr() and substr_replace() can be used when you want to extract or replace more than 1 character.

Note: As of PHP 7.1.0, negative string offsets are also supported. These specify the offset from the end of the string. Formerly, negative offsets emitted E_NOTICE for reading (yielding an empty string) and E_WARNING for writing (leaving the string untouched).

Note: Prior to PHP 8.0.0, strings could also be accessed using braces, as in $str{42}, for the same purpose. This curly brace syntax was deprecated as of PHP 7.4.0 and no longer supported as of PHP 8.0.0.

关于PHP:字符串索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/885241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com