I have a simple php code for echo all variables in same name, I troubled to echo all variables. Here is my code
<?php
$name="Baskaran";
$name="Udhayakumar";
$name="Venkatesh";
$name="Karthikeyan";
$names=array($name);
foreach($names as $value){
echo $value . "<br>";
}
?>
In this code print only last name, Please guide me
>Solution :
Each time you do $name= "name" you overwrite the previous entry in that variable.
You should start out with writing them into an array like so:
$names = []; // First create an empty array
$names[] ="Baskaran"; // Then add an entry to the first available key in that array
$names[] ="Udhayakumar"; // Repeat this
$names[] ="Venkatesh";
$names[] ="Karthikeyan";