PHP curly braces in array notation

前端 未结 5 1527
南笙
南笙 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条回答
  •  甜味超标
    2020-11-30 12:39

    According to this comment on the documentation, it is just another notation, probably designed to resemble the Perl syntax: http://www.php.net/manual/de/language.types.array.php#99015

    Update: When this answer was originally posted, the PHP manual did not have any official information on this notation. By 2014, however, the comment referenced above had been removed and, as Pacerier's answer says, the notation has been given official mention in the manual.

提交回复
热议问题