Leonardo Sapuy
Leonardo Sapuy

Reputation: 2740

Get values of array with dynamically named

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?

Upvotes: 1

Views: 34

Answers (1)

Darren
Darren

Reputation: 13128

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

Upvotes: 2

Related Questions