Reputation: 11429
I have the following code:
print $node->field_carousel_1[0]['filepath'];
What i would like to do is change the 1 and use a variable instead.
Do you have any idea how i would be able to do this?
What i am aiming for: Using a variable instead of the one to create a looping function to print field_carousel_1, field_carousel_2, field_carousel_3 etc
Upvotes: 0
Views: 67
Reputation: 24750
You can try something like this:
for ($i=1; $i<4; $i++) {
$field = "field_carousel_$i";
$arr = $node->$field;
print $arr[0]['filepath'];
}
Upvotes: 4
Reputation: 4522
I would store these in an array.
field_carousel=array('value1', 'value2', 'value3', 'etc.')
To print them, you would do...
foreach(field_carousel as $item) {
echo $item
}
Upvotes: 0