Chappers Posted November 8, 2008 Share Posted November 8, 2008 Hi, I know you can make an array containing multiple values, and print them, like this: $folder = array("hello", "world"); foreach ($folder as $contents) { echo "$contents<br>"; } and I know you can make an array in which you can keep adding single values, like this: $folder[] = "hello"; $folder[] = "world"; foreach ($folder as $contents) { echo "$contents<br>"; } but how do you make an array that you can keep adding multiple values to? This doesn't work, as it outputs the array() as "Array" followed by "and goodbye": $folder[] = array("hello", "world"); $folder[] = "and goodbye"; foreach ($folder as $contents) { echo "$contents<br>"; } and you can't add more than one value using the format $folder[] = "whatever", "whatever"); as it brings up a server error. Is there a simple answer? Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/131975-quick-array-question/ Share on other sites More sharing options...
php.ajax.coder Posted November 9, 2008 Share Posted November 9, 2008 You need to add an index value to the array statement see code: $folder[0] = "hello"; $folder[1] = "world"; foreach ($folder as $contents) { echo "$contents<br>"; } Link to comment https://forums.phpfreaks.com/topic/131975-quick-array-question/#findComment-685762 Share on other sites More sharing options...
Andy-H Posted November 9, 2008 Share Posted November 9, 2008 $folder = array("hello", "world"); $folder[] = "and goodbye."; foreach($folder as $contents){ echo $contents . '<br>'; } Link to comment https://forums.phpfreaks.com/topic/131975-quick-array-question/#findComment-685766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.