Link to home
Start Free TrialLog in
Avatar of breeze351
breeze351

asked on

Dynamic varibles

I created an array with dynamic names.  It worked, but I can't retrieve it.


	echo "count = ".$count."<br>";
	echo "f35 = ".$Floor_Desc35[0]."<br>";
	echo "f35-1 = ".$Floor_Desc35[1]."<br>";
	echo "fr1 = ".${"Floor_Desc".$count}."[0]<br>";

Open in new window


I get this result:

count = 35
f35 = 35
f35-1 = 9000
fr1 = Array[0]

Everything is correct except for fr1.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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
Avatar of ES Cheong
ES Cheong
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of breeze351
breeze351

ASKER

Thanks, that works