Connecting Tech Pros Worldwide Forums | Help | Site Map

How to get variable name like in php code?

lfx
Guest
 
Posts: n/a
#1: Sep 18 '08
Hi, I wonder how to get php variable name like in code?

I have function like this:

function printr($in){
echo "<pre>";
print_R($in);
echo "</pre>";
}

But I want get and var name to have result like this:

var: $array
Array (
[1] =a
[2] =b
[3] =c
)

Is there any solution?

Thanks

sheldonlg
Guest
 
Posts: n/a
#2: Sep 18 '08

re: How to get variable name like in php code?


lfx wrote:
Quote:
Hi, I wonder how to get php variable name like in code?
>
I have function like this:
>
function printr($in){
echo "<pre>";
print_R($in);
echo "</pre>";
}
>
But I want get and var name to have result like this:
>
var: $array
Array (
[1] =a
[2] =b
[3] =c
)
>
Is there any solution?
>
Thanks
printr($foo, 'foo');

function printr($in, $name){
echo "<pre>";
echo 'var: ' . $name;
print_R($in);
echo "</pre>";
}
lfx
Guest
 
Posts: n/a
#3: Sep 18 '08

re: How to get variable name like in php code?


Thanks, but this solution is not for me.
Is there other method?


On Sep 18, 2:54*pm, sheldonlg <sheldonlgwrote:
Quote:
lfx wrote:
Quote:
Hi, I wonder how to get php variable name like in code?
>
Quote:
I have function like this:
>
Quote:
function printr($in){
* *echo "<pre>";
* *print_R($in);
* *echo "</pre>";
}
>
Quote:
But I want get and var name to have result like this:
>
Quote:
var: $array
Array (
[1] =a
[2] =b
[3] =c
)
>
Quote:
Is there any solution?
>
Quote:
Thanks
>
printr($foo, 'foo');
>
function printr($in, $name){
* * *echo "<pre>";
* * *echo 'var: ' . $name;
* * *print_R($in);
* * *echo "</pre>";
>
}
>
>
Sjoerd
Guest
 
Posts: n/a
#4: Sep 18 '08

re: How to get variable name like in php code?


On Thu, 18 Sep 2008 00:20:38 -0700, lfx wrote:
Quote:
Hi, I wonder how to get php variable name like in code?
There was a thread last week about this:

Subject: Finding the name of a variable used in the caller of a function
from within the function itself.
From: Erwin Moller
Date: Thu, 11 Sep 2008 11:04:10 +0200
http://groups.google.com/group/comp....hp/browse_frm/
thread/7aae7a3f2e88a131/eaf109dbd65e7a0a?#eaf109dbd65e7a0a
Closed Thread