I wan't to add values continuously in a while loop in associative array. I have used the following technique, but when I am displaying it, it stores the last value only and by searching I have found out that people do the same. What is the problem in the code?
My Php code is:
while($row2=mysqli_fetch_array($result2))
{
$first=$row2['MDid'];
$second=$row2['MD_FullName'];
$data=array($first=>$second);
}
var_dump($data);
My Output is:
array(75) { [0]=> array(1) { ["AB0001"]=> string(29) "Arthur Boshnack, M.D, F.A.C.G" } [1]=> array(1) { ["AJ0001"]=> string(16) "Anwer Jaffri, MD" } [2]=> array(1) { ["AK0001"]=> string(16) "Dr.Adam Kotowski" } [3]=> array(1) { ["ALZ001"]=> string(22) "Kheir Al-Zouhayli, M.D" } [4]=> array(1) { ["AM0001"]=> string(17) "Dr.Ambrose Mgbako" } [5]=> array(1) { ["AMW001"]=> string(21) "Dr.Audrey M. Weissman" } [6]=> array(1) { ["AN0001"]=> string(25) "Dr.Anthony Napolitano,M.D" } [7]=> array(1) { ["BS0001"]=> string(17) "Bhupendra Shah,MD" } [8]=> array(1) { ["BT0001"]=> string(19) "Dr.Birendra Trivedi" } [9]=> array(1) { ["CA0001"]=> string(14) "Claudia Aroche" } [10]=> array(1) { ["CG0001"]=> string(13) "Dr.Cary Golub" } [11]=> array(1)
But when I echo:
$data["VSV001"]
I get nothing
$data[$first]= $second;..$data[] = array($first=>$second);(depending on exactly what you want to do)