I have some array:
array
0 => string 'Apple'
1 => string 'banana'
2 => string 'Nanas'
3 => string 'Grape'
What is the best way to display
1. Apple 2. banana 3. Nanas 4. Grape
Any Ideas?
I have some array:
array
0 => string 'Apple'
1 => string 'banana'
2 => string 'Nanas'
3 => string 'Grape'
What is the best way to display
1. Apple 2. banana 3. Nanas 4. Grape
Any Ideas?
How about this?
foreach($fruits as $index => $fruit) {
echo ($index+1).". ".$fruit."\n";
}
If the output you are after is HTML, then an ordered list makes sense:
<ol>
<?php foreach($fruits as $fruit) { ?>
<li><?php echo $fruit; ?></li>
<?php } ?>
</ol>
If HTML
<ol>
<?php
foreach ($fruits as $fruit) {
echo "<li>", $fruit;
}
?>
</ol>