I\'m performing a request on a database which returns an array
. I\'m using a foreach
loop to go through the values.
Database
By default, mysqli_fetch_array()
returns both an Associative Array ($key => $value
) and a Numeric Array (0 => value
), which is why you're getting duplicates - some of the entries have the column name as the key, the others have a numeric index.
If you want an associative array, you could use:
mysqli_fetch_array($q, MYSQLI_ASSOC);
//or
mysqli_fetch_assoc($q);
Or for a numeric array:
mysqli_fetch_array($q, MYSQLI_NUM);
//or
mysqli_fetch_row($q);
For more info: http://www.php.net/manual/en/mysqli-result.fetch-array.php