473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to get variable name like in php code?

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
3 4718
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Geoff Winsor | last post by:
Hi, I am experiencing a problem with recalling a session variable which stores whether a person is logged in to a "members only" section of a website. This area of the site has been working...
7
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename();...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
10
by: Blaxer | last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be... function Calculate_Something(ByVal...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
16
by: John | last post by:
Does the length of my C variable names have any affect, performance-wise, on my final executable program? I mean, once compiled, etc., is there any difference between these two: number = 3; n =...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
2
by: Looch | last post by:
All, I'm trying to output but I can only get (brackets for clarity) when using the code below. How can I "break" into the query variable in the InsertName method to add the name parameter to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.