IT Community - Software Programming, Web Development and Technical Support

Can I get a variable name as a string?

This is a discussion on Can I get a variable name as a string? within the PHP Programming forums, part of the Web Development category; I've searching in php and perl for this: how do i get a variable name as a string e....


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 02-25-2007, 02:44 AM
montyauto montyauto is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 55
montyauto is on a distinguished road
Thumbs up Can I get a variable name as a string?

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?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-02-2007, 01:38 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: Can I get a variable name as a string?

Hi
In PHP no built in function for this issue, but we can create a User

defined function for this issue


PHP Code:
function getVarName(&$pmVar$pmscope=false$pmPrefix='unique'$pmSuffix='value')
  {
    if(
$pmscope
        
$vValue $pmscope;
    else      
        
$vValue $GLOBALS;
        
$vOldVal $pmVar;
        
$pmVar $vNewVal $pmPrefix.rand().$pmSuffix;
        
$vRetName FALSE;
        
    foreach(
$vValue as $vKeyVal => $vValue
    {
      if(
$vValue === $vNewVal$vRetName $vKeyVal;
    }
    
$pmVar $vOldVal;
    return 
$vRetName;
  } 
Function Calling


PHP Code:
    $vGetName "PHP Is Web Programming Language"
   echo 
getVarName($vGetName); // Outputs:  vGetName 
Thanks
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/284-can-i-get-variable-name-string.html
Posted By For Type Date
DiscussWeb IT Community - Fusing This thread Refback 08-02-2007 03:25 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is diffrenece between string.compare and string.compareordinal shaalini ASP and ASP.NET Programming 3 12-28-2007 10:46 PM
how to pass and retrieve variable(query string) in same page using ajax? ursklakshmanan PHP Programming 0 09-17-2007 12:05 PM
Getting substring of the string variable in silk test senthilkannan Testing Tools 0 07-30-2007 03:37 AM
How to split a string by using a string usually in the c# dotnet... Archer C# Programming 1 07-25-2007 03:26 AM
Static Global Variable and Static Local Variable vigneshgets C and C++ Programming 1 05-30-2007 11:50 AM


All times are GMT -7. The time now is 02:24 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0