breeze351
asked on
Dynamic varibles
I created an array with dynamic names. It worked, but I can't retrieve it.
I get this result:
count = 35
f35 = 35
f35-1 = 9000
fr1 = Array[0]
Everything is correct except for fr1.
echo "count = ".$count."<br>";
echo "f35 = ".$Floor_Desc35[0]."<br>";
echo "f35-1 = ".$Floor_Desc35[1]."<br>";
echo "fr1 = ".${"Floor_Desc".$count}."[0]<br>";
I get this result:
count = 35
f35 = 35
f35-1 = 9000
fr1 = Array[0]
Everything is correct except for fr1.
When you use echo to print an array, the output is "Array." This has been the way PHP does it (and does it wrong) since 2002, when I first discovered it, or earlier. Try using var_dump() to print your variables and see if that gets you more sensible information.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It looks like $Floor_Desc35 may be the 35th data element in a collection, but that's just a guess. If you use var_dump() to print the variable $Floor_Desc35, and post the output here, we can show you exactly how to use it in your PHP code. We can probably also show you a data structure (such as an array of objects) that will be easier to understand and test.
If you have other $Floor_Desc variables with numbers suffixed to their names, then you've got a data structure that should be an array instead of a bunch of differently named variables. We can help with that once we see the details of the data structure.
If you have other $Floor_Desc variables with numbers suffixed to their names, then you've got a data structure that should be an array instead of a bunch of differently named variables. We can help with that once we see the details of the data structure.
ASKER
Thanks, that works