473,908 Members | 6,345 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 17637
> 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
4324
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
2879
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
3777
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
10229
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
3211
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 $_GET variable (when someone hand-types the item into the line and makes a simple typing error).
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
7450
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. Each Directory object creates an array of Subdirectories each of which has an array of...
2
2521
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
10035
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 out on reading the array values into variables so that i can do something depends on the result...
33
7207
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 would think of initialising C with:
0
11337
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10913
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10536
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8094
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7246
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6134
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3355
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.