Search code examples
phpimplode

explode function return array with serial number


I have an array like this $arr = Array ("A","E","I","O","U");

My question is using implode function how can I make the output like this

1.A
2.E
3.I
4.O
5.U

Solution

  • 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:

    1.A 
    2.E 
    3.I 
    4.O 
    5.U 
    

    Hope this helps!