如何到达有空格的变量变量?

How to reach variable variables which has spaces?

我很好奇如何访问包含空格或特殊字符的变量。

有什么办法吗?

<?php
$first_day = "monday";
$$first_day = "first day of the week";
echo $monday." <br />";
$days = 'saturday sunday';
$$days = 'days of the weekend';
// how to echo $days of the weekend ???
print_r(get_defined_vars());

根据PHP docs

A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

也就是说,严格来说,包含空格或特殊字符的变量名不是有效的变量名。

也就是说,@mario 的评论提供了解决方法:

echo ${'saturday sunday'}; // echoes 'days of the weekend'