This is a discussion on Can I get a variable name as a string? within the Coding Help forums, part of the Webmaster Help category; I've searching in php and perl for this: how do i get a variable name as a string e.g i ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I've searching in php and perl for this: how do i get a variable name as a string e.g i have a variable myvar:1 2 5 3 2 6 7 8 i want to get "myvar" Is there any function to get the name of a variable based on its value?
__________________ EXPOSE Your ADS OVER 400,000 Webs For FREE! |
| |||||
| It seems kind of backwards, but of course possible: Code: <?php
function get_var( $search )
{
$def = $GLOBALS;
foreach( $def as $k=>$d )
{
if( is_string( $GLOBALS[$k] ) && $d==$search )
{
return $k;
}
}
return false;
}
?>
Code: <?php $something = 'test var'; $varname = 'more test var'; echo get_var( 'test var' ); |
| ||||
| Quote:
thank you. |
| Tags |
| string, variable |
| Thread Tools | |
| Display Modes | |
|
|
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| clean up a string (123..9) | louie | Coding Help | 1 | 11-01-2007 12:58 PM |
| ||||||||
| | ![]() | |||||||