Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:19:25+00:00 2026-05-30T08:19:25+00:00

I am theming a drupal content type, and I have a set of similarly

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:19:26+00:00Added an answer on May 30, 2026 at 8:19 am

    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:

    <?php
    $numbers = array(123,235,12332,2342);
    
    for($i; $i<count($numbers); $i++){
        $var = "field_anp_".$numbers[$i];
        printf("%s\n", ${$var}[0]['value']);
    
    }
    ?>
    

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new to drupal theming. i want to do the following: i have
I want basic theming support in my Symfony2 project, so I wanted to have
I want some content to only be printed in my node-type.tpl.php if the node
I came across a strange behavior while theming Drupal. I turned a few modules
I've been reading about Drupal theming and preprocess functions and noticed they listed engineName
I tried theming of radios in Drupal module overriding the following code in my
I'm in the process of theming a node form. I want authenticated users to
I'm new to WordPress theming and have downloaded the Starker's WP theme from starkers
I´m trying to upgrade a big D6 site to D7. I have the content
I am theming some report tables and do not have access to the templates.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.