在PHP中,$还有其他用途吗?为什么不是';这段代码不会产生错误吗?

在PHP中,$还有其他用途吗?为什么不是';这段代码不会产生错误吗?,php,Php,在PHP中,以下代码不会产生语法错误。作为一名开发人员,这将在我的头脑中产生一个语法错误。有线索吗 <?php $ $ $ $ $ $ $what_the_hell_php = 'what is wrong with you PHP?'; echo $what_the_hell_php; // no output echo $ $ $ $ $ $ $what_the_hell_php; // worth a try but no output too // echo $; // wel

在PHP中,以下代码不会产生语法错误。作为一名开发人员,这将在我的头脑中产生一个语法错误。有线索吗

<?php
$ $ $ $ $ $ $what_the_hell_php = 'what is wrong with you PHP?';

echo $what_the_hell_php; // no output
echo $ $ $ $ $ $ $what_the_hell_php; // worth a try but no output too

// echo $; // well, don't do this. this produces an actual PHP syntax error.

$dollars = 'a lot of money will make me crazy';
echo $dollars;
echo $$$$$$$$$$$$$$$$$$$$$$$$$$ $lotsofmoney = " - and PHP too!";

// echo $$$$$$something $hello = 'hello'; // won't work, PHP likes pure dollars

// is it for this??
echo 

   $$$     $$$$$$   $$$$$$  $$$$ $$$$       $$$    $$$$$$$$  $$$$$$$$
  $$ $$   $$    $$ $$    $$  $$   $$       $$ $$   $$     $$    $$
 $$   $$  $$       $$        $$   $$      $$   $$  $$     $$    $$
$$     $$  $$$$$$  $$        $$   $$     $$     $$ $$$$$$$$     $$
$$$$$$$$$       $$ $$        $$   $$     $$$$$$$$$ $$   $$      $$
$$     $$ $$    $$ $$    $$  $$   $$     $$     $$ $$    $$     $$
$$     $$  $$$$$$   $$$$$$  $$$$ $$$$    $$     $$ $$     $$    $$

$ascii = "<hr />\nMy ASCII art is not a string or a comment! First time!";

?>

。。。以及输出:

a lot of money will make me crazy - and PHP too!<hr />
My ASCII art is not a text or a comment! First time!
很多钱会让我发疯——还有PHP
我的ASCII艺术不是文本或注释!第一次!
PHP有一个“”的概念,它允许您根据变量的名称动态引用变量。例如:

$a = 'foo';
$b = 'a';
$c = 'b';
$d = 'c';

echo $ $ $ $d; // foo
当你在作业中使用它的时候?希望这将有助于证明:

$a = 'foo';
$$a = 'bar';

echo $foo; // bar
所以在这段代码中:

echo $ $ $ $ $ $ $what_the_hell_php = 'what is wrong with you PHP?'
要分配值,引擎将获取当前存储在
$what_the_hell_php
中的值,然后获取存储在具有该名称的变量中的值,然后获取存储在具有该名称的变量中的值,依此类推。当然,在您的示例中,
$what_the_hell_php
最初为空,因此它实际上无法取消引用这些变量。但是,赋值表达式的结果仍然是一个值,就像所有赋值表达式一样:

echo $a = $b = $c = 'foo'; // foo