Creating a new variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Creating a new variable

Post by aceconcepts »

Hi,

How would one assign values to a dynamically created variable?

Normally one would declare a variable before it is used. However, if you have a foreach loop can you create a variable for each value found in an array

i.e.

Code: Select all

foreach($arrArray as $varValue)
{
   if(array_search("someValue", $otherArrayToSearch)===true) create new variable here from $varValue;
}
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Variable variables would be better here, although I don't like using either.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

just about anything that can be done with variable variables can be done better with an array.

Why do you need to extract values from the array in the first place?
Post Reply