I've been following this intro to CS course.
When I was learning C, I learned about hash tables.
Hash tables are arrays that require a hash function to map a "key" to an integer value. The value would be the index in the array.
"Key" -> [Hash function] -> value
array[value] = "Key"
Now, I'm learning about PHP, and I'm very confused about the use of associative arrays. In PHP we pass in a key (e.g. $_POST["key"] and it'll provide us with a value. So here the "key" is the index of the array, unlike the C hash table where they index was the value outputted by the hash function.
$_POST["key"] = Value
I've done a lot of searching and understand that hash tables and associative arrays are not 100% the same, but I'm very confused why these two different scenarios are using the terms "key" and "value" in different ways.
Am I seeing something wrong here?
"key" and "value" do not mean the same thing.
The key is the thing you feed into a hash table or PHP associative array or, generically, "map" to get back a value.
The confusion you're running into is that the value you get back from the hash table in your first example is then being used as a key (an array index) to a different thing (the array). Just as a person can be both a parent and a child, a number (or whatever) can be both a key (in one thing) and a value (in something else). It's a matter of what its role is in relation to the thing you're using it with.