| | |
Variable variables with dynamic array
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2009
Posts: 11
Reputation:
Solved Threads: 1
Hello everyone,
i have a little problem with variable variables if the variable is an multidimensional array and the indexes are not fix so, they are dynamic.
I need something like this:
To be more specific, the array looks like this (the last pair of [] is empty as i'd like to add new members to the array too):
To store my current location in the array, I use another one (simple 1D array)
I have been coding for a few years in php data processing apps, but never had to solve this kind of thing :-)
Thanks for any help, if you need more information let me know pls.
i have a little problem with variable variables if the variable is an multidimensional array and the indexes are not fix so, they are dynamic.
I need something like this:
php Syntax (Toggle Plain Text)
$varName = "data"; $varIndex = "[1]['items'][4]['items'][]"; ${varName.$varIndex} = 'xyz' ; // this does not work as php looks for a wrong variable, it takes the whole string as the var name.
To be more specific, the array looks like this (the last pair of [] is empty as i'd like to add new members to the array too):
php Syntax (Toggle Plain Text)
$data = array( [0] => array( //lets call this one item 'name' => Name, 'attribute' > Attribute, 'items' => array() // here can be x more items containing y more items
To store my current location in the array, I use another one (simple 1D array)
I have been coding for a few years in php data processing apps, but never had to solve this kind of thing :-)
Thanks for any help, if you need more information let me know pls.
0
#2 31 Days Ago
Try:
The two dollar signs I think is what you'll need, though I have never tried it with indexes like this.
hope that helps.
PHP Syntax (Toggle Plain Text)
$myVar = "data[1]['items'][4]['items']"; $$myVar = 'xyz';
The two dollar signs I think is what you'll need, though I have never tried it with indexes like this.
hope that helps.
Don't pay data charges. txtFeeder.com is a free way to read the web on your mobile, and avoid data charges! **Now txtFeeder has a wireless note feature! Make notes on the go!
-Kyle Getson
-Kyle Getson
0
#4 30 Days Ago
You either need to use eval (which is slow and has security risks if not used properly) or you loop through the array until you get to the index you want.
Here is an example. You should find what you are looking for there.
http://www.daniweb.com/forums/thread191093.html.
Here is an example. You should find what you are looking for there.
http://www.daniweb.com/forums/thread191093.html.
Google is your friend.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
Use [code] tags.
If you have found a solution to your problem, please mark the thread as SOLVED.
![]() |
Similar Threads
- Dynamic array => dropdown issues... (PHP)
- Programming in VBA reading file into dynamic array (VB.NET)
- How do i want to create random number for dynamic array variables ? (Visual Basic 4 / 5 / 6)
- Dynamic array of objects within an object (C++)
- Dynamic Array to Static Array (C++)
- How to Get 2D Dynamic array input in Function?? (C++)
- dynamic array variable.. (PHP)
- Error when calling a method of dynamic array (C++)
- Using php variables inside an array (PHP)
Other Threads in the PHP Forum
- Previous Thread: populating drop down menu from MySQL
- Next Thread: How to capture the screen shot of the webpage
| Thread Tools | Search this Thread |
apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code cron curl database dataentry date display duplicates dynamic ebooks echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google href htaccess html image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching mediawiki menu mlm multiple mysql number oop paypal pdf php phpincludeissue problem query radio random recursion recursive remote script search server sessions shot sms source sp space speed sql subdomain subscription syntax system table tag tutorial tutorials update upload url validator variable vbulletin video web white youtube






