Trying to generate incremental numbers in a function with foreach <p>This function creates <code>&lt;li&gt;</code> tags and im trying to give each <code>li</code> tag a unique CSS class name, I've tried to create a <code>for</code> loop to generate numbers but this is producing the number 7 rather than counting down to the number 7 in <code>&lt;li&gt;</code> tag. </p> <p>any help greatly appreciated!</p> <pre><code>function the_meta() { if ( $keys = get_post_custom_keys() ) { echo "&lt;ul class='post-meta'&gt;\n"; //tried to add this counter here to generate incremental numbers in the foreach loop for ($i = 0; $i &lt;= 6; $i++) { } foreach ( (array) $keys as $key ) { $keyt = trim($key); if ( is_protected_meta( $keyt, 'post' ) ) continue; $values = array_map('trim', get_post_custom_values($key)); $value = implode($values,', '); echo apply_filters('the_meta_key', "&lt;li class='$i'&gt;&lt;span class='post-meta-key'&gt;$key:&lt;/span&gt; $value&lt;/li&gt;\n", $key, $value); } echo "&lt;/ul&gt;\n"; } } </code></pre>