I have an array like this $arr = Array ("A","E","I","O","U");
$arr = Array ("A","E","I","O","U");
My question is using implode function how can I make the output like this
implode
1.A 2.E 3.I 4.O 5.U
You need to iterate over each values like this:
$arr = array("A","E","I","O","U"); foreach ($arr as $key => $value) { echo $key + 1 . ".{$value} <br>"; }
This will give you the desired Output as:
Hope this helps!
$i = 1; foreach ($arr as $v) { echo $i . '.' . $v . '<br>'; $i++; }
no need to use implode function. Just use foreach loop to iterate whole array.
foreach
use array_walk to traverse the array like this:
array_walk($array, function($v, $k) { echo $k + 1 . '.' . $v . "<br>"; });
You need to iterate over each values like this:
This will give you the desired Output as:
Hope this helps!