I have an array which each key is associated to an ID in my DB and the associated name.
I'm using this for posting a form which changes dynamically. How would you go about getting this data? I can do foreach, but I can only seem to get the value, without the key associated, which i need.
Thanks!
Getting position and value in an array
Moderator: General Moderators
use
that will return an array with the values as the key names, and the keys as numbers so its easy to retrieve the key names.
EG:
array {
[0] => "ID",
[1] => "name"
}
Code: Select all
$keys = array_keys($array);EG:
array {
[0] => "ID",
[1] => "name"
}
^^ doh! forgot bout that.
Code: Select all
foreach($array as $key => $value)
{}