Possible Duplicate:
Fastest way to add prefix to array keys?
I have an array that does like this:
0 => value 1,
1 => value 2,
I want to done like this:
keyname1 => value 1,
keyname2 => value 2,
In the mySQL database, all the columns have names but the array is using numbers instead of names. Is there a PHP or mySQL command that tells it how to write the keys?
In response to your comment:
You’re retrieving data from a mySQL database, so you can just fetch the data as an associative array:
PDO:
That should do it. Of course, there is
mysql_fetch_assoc, but since themysql_*extension is deprecated, I’m not going to bother with that, just switch to PDO, if you haven’t already.If you’re not comfortable with PDO for some reason, look into
mysqli_*, in which case the loop looks like this:full examples [on the doc pages](http://www.php.net/mysqli_fetch_assoc