473,385 Members | 1,521 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,385 software developers and data experts.

Turning a variable in to a string

I have:
$this_array = array($test_year, $test_color, $test_food)

I want to access another variable based on $test_year, only it will be
called $test_month (test could be something else). $test_year is a form
and I want to access $test_month.

If I use $this_array[1] then I am getting the actual value of the form.
I want to get the name of the variable I am accessing!
Aug 17 '05 #1
3 1153
On Wed, 17 Aug 2005 17:54:42 -0400, Dave Thomas wrote:
I want to get the name of the variable I am accessing!


http://php.net/manual/en/language.va...s.variable.php

--
E. Dronkert
Aug 17 '05 #2
"Dave Thomas" <ge****@hotmail.com> wrote in message
news:3b********************@adelphia.com...
I have:
$this_array = array($test_year, $test_color, $test_food)

I want to access another variable based on $test_year, only it will be
called $test_month (test could be something else). $test_year is a form
and I want to access $test_month.

If I use $this_array[1] then I am getting the actual value of the form.
I want to get the name of the variable I am accessing!


Out of your rather confusing message I am getting that you need to use
the 'key( )' array function... go to www.php.net and do a search for 'array'
and you'll get all the functions you need.

Norm
---
FREE Avatar hosting at www.easyavatar.com
Aug 18 '05 #3
Dave Thomas wrote:
I have:
$this_array = array($test_year, $test_color, $test_food)

I want to access another variable based on $test_year, only it will be
called $test_month (test could be something else). $test_year is a form
and I want to access $test_month.

If I use $this_array[1] then I am getting the actual value of the form.
I want to get the name of the variable I am accessing!

In this case it's not possible. Your array $this_array does not
store variable names.
This line of code:
$this_array = array($test_year, $test_color, $test_food)
creates array with value of $test_year being first element (index 0),
value of $test_color being second etc. As you can see only values
of those variables are stored in the array. If you are building
this array, then you could store the name too in many different
ways. Here two examples:

- As key:
$this_array = array(
'test_year' => $test_year,
'test_color' => $test_color,
'test_food' => $test_food
)
but in this case you'll have to use those names as indexes
($this_array['test_color'] instead of $this_array[1]) or
use array traversal functions.
- With subarrays:
$this_array = array(
array( 'test_year', $test_year ),
array( 'test_color', $test_color ),
array( 'test_food', $test_food )
)
but in this case you'll have to use two indexes:
$this_array[0][1] to access $test_year value and $this_array[0][0]
to get 'test_year'.
- You could also mix above methods or use objects etc.

Which method is best? That depends on what you are trying to do...

Hilarion
Aug 19 '05 #4

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

Similar topics

13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
0
by: Nadav | last post by:
Hi, The Problem: WebPermission.Demand() generate an exception ( meaning security validation has failed ), digging into the code I have stumbled upon the internal class...
1
by: Dave | last post by:
I'm have an app the opens a socket and I want the socket to stay open till the user clicks a button. I pass a string of "m_start" to start a listener, and "m_end" to the function listen_func to...
4
by: Chumley Walrus | last post by:
This may be easier than I think, but I need to find a quick way to change a datetime object to string, as the following mydateobject = mydateobject.ToString(); renders the error: Cannot...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
6
by: Paul Wagstaff | last post by:
Happy new year...hope someone can help with this.. The nub of this problem is to populate 2 tables in a 1-M relationship from an imported Excel spreadsheet. The problem being that there is...
2
tpgames
by: tpgames | last post by:
Me memory game freezes after I click some cards. I seems to be random as to the number of clicks needed before it freezes. I posted the entire code, as I am not sure what is needed for help. I am...
7
bugboy
by: bugboy | last post by:
I have a comma delineated string from an html form: "wind, sun, ocean, lake" i can use explode to turn it into an array but what i want to do is take each word and assign it to it's own...
1
by: milk242 | last post by:
So I have a program that asks the user to input their information and select services by entering 1 2 3 or etc. and it stores it as an array. This program also stores services it offers as a 2d...
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.