I have an array that is supposed to contain 100,000 items. Here is what my algorithm looks like:
$holder = array();
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
for($i = 0; $i < mysqli_num_rows($result); $i++)
{
$x = 0;
if($holder[$i]['key'] == $row["key"] && $holder[$i]['value'] == $row["value"] )
{
$x++;
}
if($x == 0)
{
$holder[$row["key"]] = $row["value"];
}
}}
}
So what it does is that it selects 'key' and 'value' from database, checks if the 'key' and 'value' occur together in this array, if they do, then do nothing, else, adds this 'key'=> 'value' to the array. The problem is that for a 100,000 lines, it takes ages to complete this process and I am in need of a quicker algorithm that does this task in short time. Any suggestions will be highly appreciated.