php_beginner_83 Posted November 25, 2009 Share Posted November 25, 2009 Hi All I'm trying to create a multidimensional array using a while loop but it's not working. When I try and print out the contents of the array, it's empty. Does anyone have any ideas what I'm doing wrong??? Thanks in advance $counter = 0; $myarray = array(); while($counter <= 5) { $myarray = array($counter, $counter + 1, $counter + 2); $counter ++; } Link to comment https://forums.phpfreaks.com/topic/182891-help-creating-a-multidimensional-array/ Share on other sites More sharing options...
Yesideez Posted November 25, 2009 Share Posted November 25, 2009 Not sure if this will work as it's off the top of my head... $arr=array(); for ($i=0;$i<5;++$i) { $arr[]=array(); } var_dump($arr); Is that what you're after? Link to comment https://forums.phpfreaks.com/topic/182891-help-creating-a-multidimensional-array/#findComment-965327 Share on other sites More sharing options...
php_beginner_83 Posted November 25, 2009 Author Share Posted November 25, 2009 Thanks Yesideez that did the trick Who would of thought just a wee set of square brackets would make the difference Link to comment https://forums.phpfreaks.com/topic/182891-help-creating-a-multidimensional-array/#findComment-965331 Share on other sites More sharing options...
php_beginner_83 Posted November 25, 2009 Author Share Posted November 25, 2009 I would make this as solved but I cant find the button anyway :S Link to comment https://forums.phpfreaks.com/topic/182891-help-creating-a-multidimensional-array/#findComment-965333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.