title: How to count each field in php
body: <p>I have the below code:</p>
  
  <pre><code>function cat_fields($fields)
  {
  global $cfg;
  $fields['cat_furl'] = str_replace('%cat_safename%', $fields['cat_safename'], $cfg-&gt;getVar('urlformat_cat'));
  $fields['cat_furl'] = $cfg-&gt;getVar('site_url') . str_replace('{cat_safename}', $fields['cat_safename'], $fields['cat_furl']);
  $fields['cat_flink'] = '&lt;a id="a'  . count($fields) .  '" href="' . $fields['cat_furl'] . '" title="' . $fields['cat_title'] . '"&gt;' . $fields['cat_name'] . '&lt;/a&gt;';
  return $fields;
  }
  </code></pre>
  
  <p>And i am trying to count each field of <code>$fields['cat_flink'] = '&lt;a id="a'  . count($fields) .  '"</code> I tried with <code>id="a'  . count($fields) .  '"</code> but it's returning the total number of field instead of counting them. How can i count them <code>EACH</code>.</p>
  
  <p>Should be </p>
  
  <pre><code>&lt;a id="a1"....&gt;
  &lt;a id="a2"....&gt;
  </code></pre>
  
  <p>Instead it's echoing me</p>
  
  <pre><code>&lt;a id="15"....&gt;
  &lt;a id="15"....&gt;
  ..... and so on
  </code></pre>
  
  <p>Please help me on this matter.</p>