PHP:$ variable {0}中的花括号有什么作用? [英] PHP: What do the curly braces in $variable{0} do?

查看:97
本文介绍了PHP:$ variable {0}中的花括号有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查一个代码库,碰到我有疑问的那一行.这是我以前从未见过的东西,我想知道是否有人可以为我解释它.这是代码:

I was going through a codebase and came across a line I had a question about. It's something I haven't seen before and I was wondering if someone could explain it for me. Here's the code:

$variableName = $array[1];
$variableName{0} = strtolower($variableName{0});
$this->property = $variableName;

花括号是用来做什么的?我之前使用花括号将变量定义为变量名,但这是同一回事吗?我似乎在网上找不到任何解释它的资源,但是我不确定是否在寻找正确的东西.

What are the curly braces being used for? I've used curly braces to define variables as variable names before, but is this the same thing? I can't seem to find any resources online that explain it, but I'm not sure if I'm searching for the right thing.

推荐答案

访问具有该索引的单个字节{0} =>第一个字符(非utf8字符串)

access the single byte with that index {0} => first char (in non-utf8 string)

您可以使用以下命令进行简单测试:

you could simply test it with:

$var='hello';
echo $var{0};

这篇关于PHP:$ variable {0}中的花括号有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆