By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

How to get variable name like in php code?

P: n/a
lfx
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
Sep 18 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
lfx wrote:
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>";
}
Sep 18 '08 #2

P: n/a
lfx
Thanks, but this solution is not for me.
Is there other method?
On Sep 18, 2:54*pm, sheldonlg <sheldonlgwrote:
lfx wrote:
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>";

}

Sep 18 '08 #3

P: n/a
On Thu, 18 Sep 2008 00:20:38 -0700, lfx wrote:
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
Sep 18 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.