aniesh82 Posted August 6, 2008 Share Posted August 6, 2008 Hi, I used the variable -variable concept to create dynamic array names.. but it is not working like I expected.. <?php #dynamicarray.php for($i=1;$i<=5;$i++) { $name = 'b'.$i; $$name[] = 10; } print_r($b1); /** Expected Output is: $b1[] = 10; $b1[] = 10; $b2[] = 10; $b2[] = 10; */ ?> Link to comment https://forums.phpfreaks.com/topic/118508-solved-variable-variable-array/ Share on other sites More sharing options...
effigy Posted August 6, 2008 Share Posted August 6, 2008 Use ${$name}[]. Why not create an array of arrays? Link to comment https://forums.phpfreaks.com/topic/118508-solved-variable-variable-array/#findComment-610099 Share on other sites More sharing options...
aniesh82 Posted August 6, 2008 Author Share Posted August 6, 2008 Hi, Its working.. thank you so much for your reply & suggestion.. I need to create separate variables for each arrays thats why I used this method. Link to comment https://forums.phpfreaks.com/topic/118508-solved-variable-variable-array/#findComment-610121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.