PHP curly braces in array notation

前端 未结 5 1526
南笙
南笙 2020-11-30 12:20

I\'d just come across a very weird bit of php code:

$oink{\'pig\'} = 1;
var_dump($oink);

$oink{\'pig\'} = \'123123\';
echo $oink{\'pig\'}; /* => 123123 *         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 12:58

    It is mentioned in the manual, but it's obscure:

    http://www.php.net/manual/en/language.types.string.php#language.types.string.substr

    In a nutshell, the curly braces access only a single character (try adding a full string and you'll see it returns only the first character). It is also deprecated, so I would avoid it's use.

提交回复
热议问题