Need key() equivalent for string variable

From: Date: Mon, 22 Jan 2001 15:10:06 +0000
Subject: Need key() equivalent for string variable
Groups: php.general 
Request: Send a blank email to php-general+get-36011@lists.php.net to get a copy of this message
I'm trying to pass a string variable to a custom function, echoing its *value on one line, and its *name (that is, its key if this were an array instead of a string) on another line. I searched the manual's sections on variable functions and string functions, to no avail. I tried key(), but it just produces a warning that $var is not an array. Example: build_select_menu($display,array("Y","N")); function build_select_menu($field,$options_array) { echo '<p><SELECT NAME="' . key($field) . '">' . "\n"; //need to echo name of string passed as first argument foreach($options_array as $option) { echo '<OPTION VALUE="Y"'; if($field=="$option") {echo ' SELECTED';} echo ">$option</OPTION>\n"; } echo "</SELECT></p>\n"; } Thanks! -- CC

« previous php.general (#36011) next »