473,585 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array name

hi all,

I've got a simple array named my_array :
my_array = array();

I'd like to display the name of my array => print .... I can't find !
how is it possible ?

many thanks in advance,
--
roland
Jul 17 '05 #1
12 17586
> I've got a simple array named my_array :
my_array = array();


oups... it should be :
$my_array = array();

sorry,
--
roland
Jul 17 '05 #2
roland:
hi all,

I've got a simple array named my_array :
my_array = array();

I'd like to display the name of my array => print .... I can't find !
how is it possible ?

many thanks in advance,


echo "my_array";

André Nęss
Jul 17 '05 #3
>
echo "my_array";

André Nęss


ah ah !
No, I'd like to find a way to get the name of the array dynamicaly.
something like echo $my_array.get_t he_name_of_the_ array();

--
roland
Jul 17 '05 #4
roland:

echo "my_array";

André Nęss


ah ah !
No, I'd like to find a way to get the name of the array dynamicaly.
something like echo $my_array.get_t he_name_of_the_ array();


But if you type $my_array you already know the name of the variable. What is
it *really* you are trying to achieve? When people ask these kinds of
questions it's almost always because they are on the wrong track.

André Nęss
Jul 17 '05 #5
> But if you type $my_array you already know the name of the variable. What
is
it *really* you are trying to achieve? When people ask these kinds of
questions it's almost always because they are on the wrong track.

OK, in fact, I summed up my coding pb in order not to have a too long
message.

Actually, I've got a function with the following prototype :
function my_function ($my_array);
$my_array is an array
As this function is called from different files, the array name changes.
I'd like to avoid :
function my_function ($my_array, $array_name);
I find it "dirty"...
I'd like to use the first prototype and being able to get the name of the
array $my_array in the function.

Is that clearer to you ?
thanks for your help,
--
roland
Jul 17 '05 #6
"roland" <ro****@no-spam.org> wrote:
But if you type $my_array you already know the name of the variable.
What

is
it *really* you are trying to achieve? When people ask these kinds of
questions it's almost always because they are on the wrong track.

Actually, I've got a function with the following prototype :
function my_function ($my_array);
$my_array is an array
As this function is called from different files, the array name
changes. I'd like to avoid :
function my_function ($my_array, $array_name);
I find it "dirty"...
I'd like to use the first prototype and being able to get the name of
the array $my_array in the function.


Hi Roland,

It's clear what you want to achieve, but why do you need to know the
variable's name?

(BTW, without somehow passing the name of the variable to your function it
is not possible)

JOn
Jul 17 '05 #7
roland wrote:
But if you type $my_array you already know the name of the variable.
What is it *really* you are trying to achieve? When people ask these
kinds of questions it's almost always because they are on the wrong
track.

OK, in fact, I summed up my coding pb in order not to have a too long
message.

Actually, I've got a function with the following prototype :
function my_function ($my_array);
$my_array is an array
As this function is called from different files, the array name
changes. I'd like to avoid :
function my_function ($my_array, $array_name);
I find it "dirty"...
I'd like to use the first prototype and being able to get the name of
the array $my_array in the function.

Is that clearer to you ?
thanks for your help,


[Obi Wan tone on]
You dont need to know the name of the variable.
[Obi Wan tone off]
You are going on the wrong track somewhere indeed. Why would you
possibly need the name of the variable? Give us the bigger picture of
what you are doing, and we can better show you a way to do it without
odd twinkets.

--
Suni

Jul 17 '05 #8
Roland,

what about:

$arraysByName['myArray'] = array();

//mak the call
myFunction(arra ySliceByKey($ar raysByName, 'myArray', 1));

//define the function
function myFunction($arr ayOfOneArrayByN ame)
{
forEach($arrayO fOneArrayByName as $arrayName => $anArray) {
//your statements
}
}

function arraySliceByKey ($array, $key, $length)
{
return array_slice( $array, array_search($k ey, array_keys($arr ay)),
$length);
}
BTW, I could not find a function to get the index of a key in an array
(needed for array_slice).
array_search and array_keys will be slow if $arraysByName is large. The
following would be a lot faster:

function arraySliceOneBy Key($array, $key)
{
return array($key => $array);
}

Greetings,

Henk Verhoeven,
www.metaclass.nl

"roland" <ro****@no-spam.org> wrote in message
news:3f******** **************@ news.free.fr...
But if you type $my_array you already know the name of the variable.
What is
it *really* you are trying to achieve? When people ask these kinds of
questions it's almost always because they are on the wrong track.

OK, in fact, I summed up my coding pb in order not to have a too long
message.

Actually, I've got a function with the following prototype :
function my_function ($my_array);
$my_array is an array
As this function is called from different files, the array name changes.
I'd like to avoid :
function my_function ($my_array, $array_name);
I find it "dirty"...
I'd like to use the first prototype and being able to get the name of the
array $my_array in the function.

Is that clearer to you ?
thanks for your help,
--
roland

Jul 17 '05 #9
If you absolutely must know the identity of your variables...

function my_function ($my_array) {
$caller_info = array_shift(deb ug_backtrace()) ;
$lines = file($caller_in fo['file']);
$line = $lines[$caller_info['line'] - 1];
if(preg_match('/my_function\\s* \\(\$(\\w+)/', $line, $matches)) {
$name_of_my_arr ay = $matches[1];
echo $name_of_my_arr ay;
}

}

"roland" <ro****@no-spam.org> wrote in message news:<3f******* *************** @news.free.fr>. ..
But if you type $my_array you already know the name of the variable. What

is
it *really* you are trying to achieve? When people ask these kinds of
questions it's almost always because they are on the wrong track.

OK, in fact, I summed up my coding pb in order not to have a too long
message.

Actually, I've got a function with the following prototype :
function my_function ($my_array);
$my_array is an array
As this function is called from different files, the array name changes.
I'd like to avoid :
function my_function ($my_array, $array_name);
I find it "dirty"...
I'd like to use the first prototype and being able to get the name of the
array $my_array in the function.

Is that clearer to you ?
thanks for your help,

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
4300
by: James | last post by:
Hi, Have posted before, but will simplify problem here. For original post go to http://forums.devshed.com/t80025/s.html I have setup 2 arrays like so in my one page script: $carers = array( array('names' => 'Carer 01', 'hours' => 8, 'remaining' => 8),
5
2863
by: Nico | last post by:
Hello folks, I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist = new item("myitem"); //... and I am looking to develop a search function, which returns a reference to the found item.
4
3735
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
58
10093
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
7
3187
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends up looking for characters that wrap around the stripped characters and it ends up as a recursive ordeal that fails to identify a poorly constructed...
2
304
by: sicapitan | last post by:
I'm trying to build some xml from an array with the help from another array. In one array I have $cells Array ( =CELL0
23
7385
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion....
2
2495
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
1
9971
by: neoblitz | last post by:
Hi Guys, I'm very new to NuSoap. I'm able to call a webservice which actually returned me results.. But I'm having trouble to read the response or I simply don't understand how to read the response.. here is the code i've used to call the service. It returns a kind of big array so i'm so much lost inside it.. I would be grateful if someone help me...
33
7149
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d array, so im inputting the dimensions of those myself. The problem is that the output array (C=A*B) has as many rows as A and as many columns as B. I...
0
7832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8204
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5705
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3828
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1167
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.