I have the following loop…
for ($i = 1; $i <= 10; $i++) {
echo '<span class="srch-val-'.$i.'">'.apply_filters(" $value\n", $value)."</span>";
}
within…
while ( $query->have_posts() ) : $query->the_post();
if ( $keys = get_post_custom_keys() ) {
echo "<div class='clearfix card-prod ".($i==0?'first':'')."'><span class='card-title'>";
echo the_title();
echo "</span>";
foreach ( (array) $keys as $key ) {
$keyt = trim($key);
if ( '_' == $keyt{0} || 'pricing' == $keyt || 'vehicleType' == $keyt || 'coverageRegion' == $keyt || 'locationType' == $keyt )
continue;
$values = array_map('trim', get_post_custom_values($key));
$value = implode($values,', ');
for ($i = 1; $i <= 10; $i++) {
echo '<span class="srch-val-'.$i.'">'.apply_filters(" $value\n", $value)."</span>";
}
}
echo "\n"; echo '<img src="wp-content/themes/cafc/images/top-choice.jpg" alt="Top Choice" class="topchoice">';echo '<img src="wp-content/themes/cafc/images/cards/dummy.png" />'; echo the_excerpt()."</div>";}
$i++;
endwhile;
When I execute my code however, say my while() loop returns 4 values, my for() loop then outputs 10 of the same thing, in my browser its shown as…

All I want to do is for each <span class="srch-val'> is to add a number after each ‘srch-val’ class, so srch-val-1, srch-val-2 etc…
You have an extra for-loop inside your foreach-loop. Remove this loop and just do the echo directly inside the foreach-loop and increment
$ieach time you actually use it.Like this: