A question about associative arrays

From: Date: Fri, 13 Sep 2002 16:02:45 +0000
Subject: A question about associative arrays
Groups: php.general 
Request: Send a blank email to php-general+get-116292@lists.php.net to get a copy of this message
I've been reading through the php.net documentation about associative arrays and have a question. I understand that (and why).. $arr[key] is bad $arr['key'] is good but; what about $arr[$key] should it be $arr["$key"] To be specific, I maintain a database column name to database column label mapping.. for example.... $dbColumnMap = array ( 'first_name' => 'First Name', 'zip' => 'Zip Code' ); In my method accessor getDBColumnMap, I want to default the dbColumnMap to simply mapping the column name to itself. function getDBColumnMap() { if ( !isset($this->_dbColumnMap) ) { // if $this->setDBColumnMap(anAssocArray) was not called then default the instance variable $result = mysql_query($this->getSQLStatement(), $this->getDBConnection()); $fieldObj = mysql_fetch_field($qryResult); while ($i < mysql_num_fields($qryResult)) { $fieldObj = mysql_fetch_field($qryResult); $fieldName = $fieldObj->name; $this->_dbColumnMap[$fieldName] = $fieldName; // IS THIS EVALUATING TO A STRING OR CONSTANT? $i++; } } return $this->_dbColumnMap; } Thanks for any feedback you may have. --Hise

« previous php.general (#116292) next »