Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Displaying the name of an array when you don't actually know what it is called...!

    Heheh, yup it's an odd one

    Basically, I have written a nifty little function for debugging, that simply displays all the contents of an array, in a nice little table.

    Now, at the top of the table I want to put the name of the array... which is where I run into difficulties!

    I can't seem to find any way of actually displaying the variable name... I mean, if I pass $myArray to the function, I want the function to print "myArray" at the top of the table.

    Hmmmmm.

    Any ideas...?

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Pass the name as a second parameter to the function... or am I missing something?

    Since the array parameter your function receives is most certainly named as something - isn't that in conflict with your idea? I mean, when the array is copied into the function's local scope, it is named by the name you gave the parameter - but I guess you wanted the original variable name. But since variables names are not much more than symbols pointing to memory location, I doubt you come much far on this track.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I could pass it as a second parameter however I was hoping to do it a little more elegantly

    I didn't think this was possible (unlike in JavaScript) but I thought I may as well have a go... I could also JUST pass it as text and then evaluate that but that's messy

    ah well

    thanks for the help

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by krycek
    I didn't think this was possible (unlike in JavaScript) but I thought I may as well have a go...
    How can you do that in JavaScript? I always thought that it wasn't possible as well and would be interested to know how to get the variable's name.

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    heheh, I figured it out a while back... use the DOM to find the element.name property or some such... ask jkd, I think it was him that helped me figure it out

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It might be so clear to you, but well, I'm not that genius! how can you have the real variable name by sending it as the 2nd parameter?!

    Can you bring an example of what you wana do, because basically I think you will call your function in a for loop, right? Something like:
    PHP Code:
    foreach ( $myArr as $key => $val )
        
    myFunction$val$key ); 
    That $val is an array itself ( that you do not know it's name ) but $key holds that array's name. It's the only case that I can think of, because if you call an array yourself ( manually! ) then you already know it's name to put as the 2nd argument, huh?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •