我们如何使用 $1、$2,反之亦然?

How can we use $1, $2 and vise versa?

其实我想获取数组在不同变量中的值,所以我写了这段代码:

$count = count( $t );
$count = $count - 1;//count starts with 1 and array starts with 0

for ($i=0; $i <= $count; $i++) { 
    $$i = $t[$i];//[=10=] = something;  = something; vise versa
}
// $i = 1;
// $i++;
// $$i = ;
var_dump(,,);

我可以创建这个变量,但无法访问它们,因为 $1 不被识别为变量。

Parse error: syntax error, unexpected '1' (T_LNUMBER), expecting variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\Whosebug\test.php on line 56

我想使用 $0、$1、$2 等

PHP变量名不能以数字开头:

Variable names follow the same rules as other labels in PHP. 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]*'

来源:http://php.net/manual/en/language.variables.basics.php

您应该直接使用 $t 数组,而不是使用编号变量。

不确定您要实现的目标,但可以这样做:

$number = 1;
$$number = 'OK';

echo ;

将输出:

OK