I am receiving 40 variables from an external source into my php script.
I need to have for loop cycle through those and assign them to
variables in the php script. I am unsure of the syntax, but it would be
something like the following
for($i=0;$i<40;$i++){
$phpvar+$i = receivedData+$i
}
The data coming in is named as follows data1, data2, data3, ... data40.
So I need the php variables to be named in the same way. Whats the
syntax here? Thanks for any help. 8 1114
blackberryoctopus wrote:
The data coming in is named as follows data1, data2, data3, ...
data40. So I need the php variables to be named in the same way.
Whats the syntax here? Thanks for any help.
${"data$i"} = receivedData+$i;
But it would make more sense to create an array:
$data = array();
for ( ... ){
$data[] = receivedData+$i;
}
JW
blackberryoctopus wrote:
I am receiving 40 variables from an external source into my php script.
I need to have for loop cycle through those and assign them to
variables in the php script. I am unsure of the syntax, but it would be
something like the following
for($i=0;$i<40;$i++){
$phpvar+$i = receivedData+$i
}
The data coming in is named as follows data1, data2, data3, ... data40.
So I need the php variables to be named in the same way. Whats the
syntax here? Thanks for any help.
Data coming in from where? GET? POST? Command line? Cookies? Let's
suppose it's POST and you have POST variables named data1, data2, ...
data40. Then it would be something like this:
for($i = 1; $i <= 40; $i++) {
$name = "data$i";
$$name = $_POST[$name];
}
Message-ID: <11*********************@i56g2000hsf.googlegroups. comfrom
ZeldorBlat contained the following:
>The data coming in is named as follows data1, data2, data3, ... data40. So I need the php variables to be named in the same way. Whats the syntax here? Thanks for any help.
Data coming in from where? GET? POST? Command line? Cookies? Let's suppose it's POST and you have POST variables named data1, data2, ... data40. Then it would be something like this:
for($i = 1; $i <= 40; $i++) {
$name = "data$i";
$$name = $_POST[$name]; }
Or you could use extract
extract($_POST);
Or you could just use the array elements directly
echo $_POST['data1'];
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
There is a shorter way I think. If we assume those are POST variables, the
code might look something like
foreach ($_POST as $name =$value)
$name = $value;
"ZeldorBlat" <ze********@gmail.comwrote in message
news:11*********************@i56g2000hsf.googlegro ups.com...
>
blackberryoctopus wrote:
>I am receiving 40 variables from an external source into my php script. I need to have for loop cycle through those and assign them to variables in the php script. I am unsure of the syntax, but it would be something like the following
for($i=0;$i<40;$i++){ $phpvar+$i = receivedData+$i }
The data coming in is named as follows data1, data2, data3, ... data40. So I need the php variables to be named in the same way. Whats the syntax here? Thanks for any help.
Data coming in from where? GET? POST? Command line? Cookies? Let's
suppose it's POST and you have POST variables named data1, data2, ...
data40. Then it would be something like this:
for($i = 1; $i <= 40; $i++) {
$name = "data$i";
$$name = $_POST[$name];
}
Geoff Berrow wrote:
Message-ID: <11*********************@i56g2000hsf.googlegroups. comfrom
ZeldorBlat contained the following:
The data coming in is named as follows data1, data2, data3, ... data40.
So I need the php variables to be named in the same way. Whats the
syntax here? Thanks for any help.
Data coming in from where? GET? POST? Command line? Cookies? Let's
suppose it's POST and you have POST variables named data1, data2, ...
data40. Then it would be something like this:
for($i = 1; $i <= 40; $i++) {
$name = "data$i";
$$name = $_POST[$name];
}
Or you could use extract
extract($_POST);
Or you could just use the array elements directly
echo $_POST['data1'];
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
I know that referencing the elements directly would work, but it would
be cumbersome and in flexible for future revisions. I am trying to
avoid this; so some sort of for loop to populate an array or multiple
variables in php seemed like the best way.
I definately would suggest you to use array, as advised in the first
post. Dynamic variable -names are usually result of bad design.
Message-ID: <45********@news.bihnet.bafrom denis contained the
following:
>There is a shorter way I think. If we assume those are POST variables, the code might look something like
foreach ($_POST as $name =$value)
$name = $value;
Nearly.
foreach ($_POST as $name =$value){
$$name = $value;
}
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Yep, I saw it as well and hoped someone would correct.
Thanks.
"Geoff Berrow" <bl******@ckdog.co.ukwrote in message
news:n4********************************@4ax.com...
Message-ID: <45********@news.bihnet.bafrom denis contained the
following:
>>There is a shorter way I think. If we assume those are POST variables, the code might look something like
foreach ($_POST as $name =$value) $name = $value;
Nearly.
foreach ($_POST as $name =$value){
$$name = $value;
}
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Maciej Nadolski |
last post by:
Hi!
I`ve got a simple question but I`m puzzled:( When I create variable: for example
$query for query to MySQL its obvieus that I want to use variables. Now should I do
something like that:
1)...
|
by: Brian Sabbey |
last post by:
Here is a first draft of a PEP for thunks. Please let me know what you
think. If there is a positive response, I will create a real PEP.
I made a patch that implements thunks as described here....
|
by: Trimbitas Sorin |
last post by:
Hello
I have a simple syntax question :
What does the following line mean:
1: %checkType; ?? I know that @test="" is an array and $test="" is a
simple variable.
Thank you
With best regards...
|
by: NS Develop |
last post by:
What's wrong with the following:
void SomeClass::someMethod(void)
{
A *ptrA = NULL;
ptrA = &A();
....
}
|
by: Bshealey786 |
last post by:
Okay im doing my final project for my first computer science class(its
my major, so it will be my first of many), but anyway im a beginner so
im not to great with C++ yet. Anyway this is the error...
|
by: Mike D Sutton |
last post by:
Please excuse the terribly 'newbie'ness of this question, unfortunately my C# is very rusty..
What I'm trying to do is write a simple interactive drawing application where a few lines can be moved...
|
by: Ted |
last post by:
Here is one such function:
CREATE FUNCTION my_max_market_date () RETURNS datetime
BEGIN
DECLARE @mmmd AS datetime;
SELECT max(h_market_date) INTO @mmmd FROM holdings_tmp;
RETURN @mmmd;
END
...
|
by: aum |
last post by:
Hi,
I'm a Python programmer, just starting to get into javascript. On reading
some of the js guides, and not liking any of the OO usage patterns I saw,
I've cooked up something which python...
|
by: Hakusa |
last post by:
I have the argument items in my class room.
class room:
def __init__(self, name, description, items*):
I thought I remembered from a tutorial I read once, and I've read so
many I feel like an...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |