So I'm trying to create an array inside a loop so that I can use its elements elsewhere in the code ...
And so when I try to var_dump the array to see if all the expected elements have been added into the array , I only see the last element of the array inside the new array .. Could anyone explain me why ... Below is the relevant part of the code
$select = "SELECT * FROM DEVICES";
$result = mysql_query($select);
$result_count = mysql_num_rows($result)
if($result_count > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<td> <a class='inline' href='/profiles.php?id=".$row['ID']."'><img src='".$row['Picture']."'width='50' height='50' class ='image' /></a> <br /> <br /> <div style='color: blue; font-weight:bold; font-size:15px;'> By ".$row['Name']." </td>";
$user_array = array();
if(array_key_exists("Device",$row)){
array_push ($user_array,$row["Device"]);
}
}
}
var_dump($user_array); // only returns the last element inserted into $user_array.