Jump to content

Variable within variable name (unexpected T_VARIABLE, expecting ']')


loyx

Recommended Posts

Hey, I'm having trouble when trying to use a variable in a variable name.

 

I get the error Parse error: syntax error, unexpected T_VARIABLE, expecting ']'  when trying to do this:

 

if ($_POST[item_{$x}_num_of_supplies] != '')
...

The $x is a variable for a loop counter. Every time the loop runs I want it to access a different variable, like this:

$_POST[item_1_num_of_supplies]

$_POST[item_2_num_of_supplies]

$_POST[item_3_num_of_supplies]

$_POST[item_4_num_of_supplies]

etc etc

 

I tried putting the variables in single quotes and double quotes, and using the braces in different places but nothing seems to work, producing various errors. Does anyone know a solution?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.