print individual field inside views-view.tpl.php I need to theme my view inside views template. Inside custom views-view.tpl.php template I can add individual fields inside loop:

&lt;?php foreach ($view-&gt;style_plugin-&gt;rendered_fields as $delta =&gt; $item): ?&gt;
&lt;?php print $item['myfield1']; ?&gt;
&lt;?php endforeach; ?&gt;
//after a loop I can add any other field for custom theming like so:
&lt;?php print $item['myfield2']; ?&gt;


Question: How can I add another field before the loop is executed? I tried this:

&lt;?php print $item['myfield3']; ?&gt;
&lt;?php foreach ($view-&gt;style_plugin-&gt;rendered_fields as $delta =&gt; $item): ?&gt;
&lt;?php print $item['myfield1']; ?&gt;
&lt;?php endforeach; ?&gt;
&lt;?php print $item['myfield2']; ?&gt;


But the field3 is not rendered because the $item is not defined, I think.

I am not php programmer so I came up with a dumb workaround

&lt;?php foreach ($view-&gt;style_plugin-&gt;rendered_fields as $delta =&gt; $item): ?&gt;
&lt;?php endforeach; ?&gt;
&lt;?php print $item['myfield3']; ?&gt;
//field is rendered
&lt;?php foreach ($view-&gt;style_plugin-&gt;rendered_fields as $delta =&gt; $item): ?&gt;
&lt;?php print $item['myfield1']; ?&gt;
&lt;?php endforeach; ?&gt;
&lt;?php print $item['myfield2']; ?&gt;


What is the correct way of displaying an individual field without putting it inside foreach loop?

Thank you
You are wise to admit it before someone else points it out:  "I am not php programmer." ;)  This is a pure PHP problem, having very little to do with Drupal.

Your foreach() loop defines the variables $delta and $item.  Unlike some other languages, they are still in scope when the loop finishes, keeping the values they had at the end of the loop.

You could do something like this (untested):

&lt;?php
  $first_item = reset($view-&gt;style_plugin-&gt;rendered_fields);
  $last_item = end($view-&gt;style_plugin-&gt;rendered_fields);
  print $first_item['myfield1'];
  pring $last_item['myfield2'];
?&gt;


After the foreach() loop, $item would be the same as $last_item.

The PHP docs are pretty good:  arrays
and array functions.