Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP foreach loop question

Posted on 2011-03-02
3
Medium Priority
?
357 Views
Last Modified: 2012-05-11
Hi,

I want to increment the class name in the attached code by +1 each time it is outputted, so I end up with something like this:

catItemExtraFieldsValue1
catItemExtraFieldsValue2
catItemExtraFieldsValue3

Thanks
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
				<span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
			<?php endforeach; ?>

Open in new window

0
Comment
Question by:Eternal_Student
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 35020954
this should do:
<?php $i= 1; foreach ($this->item->extra_fields as $key=>$extraField){ ?>
   <span class="catItemExtraFieldsValue<?php echo $i++; ?>"><?php echo $extraField->value; ?></span>
<?php } //foreach ?>

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35022895
I think angelIII has answered your question, but I've got the uneasy sense that this might generate something that would cause the HTML to fail validation, or maybe generate unstyled content.  Do you have a pretty tight limit on the number of extra fields?
0
 
LVL 18

Author Comment

by:Eternal_Student
ID: 35048073
This worked just fine actually.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question