获取具有动态命名的数组的值
Get values of array with dynamically named
我正在动态获取一些文件数组的名称,我可以打印完整的数组,使用
print_r($$n_v);
输出:
Array ( [name] => 5.docx [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [tmp_name] => /tmp/php1cs872 [error] => 0 [size] => 14061 )
但如果我尝试这样做
print $$n_v['name'];
它不起作用,我怎样才能得到那个数组的值?
您可以通过利用PHP的变量变量执行以下操作来打印它:
${$n_v}['name'];
Exert 取自 PHP 变量页面:
Sometimes it is convenient to be able to have variable variable names.
That is, a variable name which can be set and used dynamically.
阅读更多关于 PHP variable variables
我正在动态获取一些文件数组的名称,我可以打印完整的数组,使用
print_r($$n_v);
输出:
Array ( [name] => 5.docx [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [tmp_name] => /tmp/php1cs872 [error] => 0 [size] => 14061 )
但如果我尝试这样做
print $$n_v['name'];
它不起作用,我怎样才能得到那个数组的值?
您可以通过利用PHP的变量变量执行以下操作来打印它:
${$n_v}['name'];
Exert 取自 PHP 变量页面:
Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically.
阅读更多关于 PHP variable variables