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

creating variables in a loop

Hi,
I want to create variables in a loop, each with a different name. Here
is the loop i'm using:
if (is_array($attribs)) {
echo "Attributes : <br />";
while(list($key,$val) = each($attribs)) {
echo $key."has the value".$val."<br>";

}
}

I want to create a variable with the name of each $key and contain the
value in $val.
Is this possible?

Jun 4 '07 #1
3 1490
Damo wrote:
Hi,
I want to create variables in a loop, each with a different name. Here
is the loop i'm using:
if (is_array($attribs)) {
echo "Attributes : <br />";
while(list($key,$val) = each($attribs)) {
echo $key."has the value".$val."<br>";

}
}

I want to create a variable with the name of each $key and contain the
value in $val.
Is this possible?
Possible (see http://www.php.net/manual/en/function.extract.php) but
pretty pointless. What's wrong with just array?
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Jun 4 '07 #2
Cheers for the help. That did the trick

Jun 4 '07 #3
On Jun 4, 10:23 pm, Damo <cormacdeba...@gmail.comwrote:
Cheers for the help. That did the trick
If that did the trick, you did something wrong designwise ;-)

But sometimes quick solutions are needed, and good design is not the
target / withing scope.

--
Jussi
Deep abstraction kills strong typing.
http://disczero.com
http://naamio.net
http://hoffburger.com

Jun 5 '07 #4

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

Similar topics

1
by: John Smith | last post by:
This might be an absurd question, but is it possible to create variables on the fly? For example, if I have an array of values myArray(0) = "foo" myArray(1) = "bar" myArray(2) = "foobar" ...
10
by: Dee | last post by:
Is C++ the best language to create a Windows based Instant Messenger? Something along the lines of MSN Messenger, ICQ, Yahoo Chat, etc? Are there any downloadable full or trial SDK's out there?...
9
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
2
by: Dave Monk | last post by:
Hi, I'm reasonably proficient in PHP but have been asked how to do something which has got me stumped. Hence, my posting: I want to create a small number of variables, $pos1, $pos2 ... $pos5...
4
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, Is there ANY way to accomplish this: (see below)? Basically, I want to have a loop (a < 3 is just for testing purposes, it will be an underermined amount). In this loop, I want to be...
1
by: joe_doufu | last post by:
I'm creating a page with multiple "widgets", each with its own XMLHttpRequest object, so the user can play with the widgets in parallel. The widgets are enclosed in divs with class "widget" and a...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
14
by: tdahsu | last post by:
I have twenty-five checkboxes I need to create (don't ask): self.checkbox1 = ... self.checkbox2 = ... .. .. .. self.checkbox25 = ... Right now, my code has 25 lines in it, one for each...
6
by: AMP | last post by:
Hello, I am trying to do the following with a loop because the amount of channels can change. uint Chan_1 = 0; uint Chan_2 = 0; uint Chan_3 = 0; uint Chan_4 = 0; uint Chan_5 = 0; uint Chan_6...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.