I am theming a drupal content type, and I have a set of similarly named variables. e.g. field_anp_1, field_anp_2,…, field_anp_10. I want to dynamically print them out from within a for loop. Normally, one would print the values out individually by doing something like:
print $field_anp_1[0]['value'];
in my case, I can’t do this because the last number changes. So, within a for loop, how would one print out these fields? I tried variable variables, but I don’t seem to understand exactly what is going on there – and I don’t think it likes the fact that this in an array. Any help would be greatly appreciated!
Ok, I figured it out. I simply needed to be more specific with PHP. To call a variable such as:
$field_anp_0[0]['value']from within a for loop, where 0 is increasing, one simply needs to do the following:This will allow me to list the fields that I will need to have printed out in the order I need to have them printed out. Then, I can use a for loop to print out a themed table for instance.
Thank you for the help!