Hi!
If you are using strings as keys, you can do the following.
// Create an array
$aTable = array();
// Use associative array to map key => value
$aTable[ "key1" ] = "Value1";
$aTable[ "key2" ] = "Value2";
$aTable[ "key3" ] = "Value3";
// Try to get som values
$sValue = $aTable[ "key2" ];
echo( $sValue );
// The following syntax also acceptable
$aTable = array
(
"key1" => "value1",
"key2" => "value2",
"key3" => "value3"
);
// Try to get som values
$sValue = $aTable[ "key2" ];
echo( $sValue );
// If you get the keys from a database you
// would do something like this:
// Fetch the data from database...
$sQuery "select key,value from table";
$hResult = mysql_query($sQuery);
// For each row:
// 1. Extract key value pair
// 2. Insert into our array
while( list($sKey, $sValue) = mysql_fetch_array($hResult) )
$aTable[ $sKey ] = $sValue;