1

I'm getting dynamically the name of some File arrays, I can print the complete array, using

print_r($$n_v);

Output:

Array ( [name] => 5.docx [type] => application/vnd.openxmlformats-officedocument.wordprocessingml.document [tmp_name] => /tmp/php1cs872 [error] => 0 [size] => 14061 )

But if I try to do

print $$n_v['name'];

It don't works, how can I get the values of that array?

1
  • The fix is simple, but: don't use variable variables to begin with. Use an array, like $data[$n_v]['name']. That's much saner in the long run. Commented Jan 14, 2015 at 5:10

1 Answer 1

2

You can print it by doing the following by harnessing PHP's variable variable:

${$n_v}['name'];

Exert taken from the PHP variable variables page:

Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically.

Example


Read more about PHP variable variables

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.