Anzeo Posted September 3, 2007 Share Posted September 3, 2007 Hey all, I'm currently working on some smaller extra's to add to my site. One of them requires me to input a list (using a form). The list is inputed through a textarea and every new line is seperated by a comma. I'm now trying to figure out how to list all those lines. I've worked out something along the lines of: $List = $_POST['List']; $Listarray = array(); list($Listarray[]) = explode(",",$List); foreach($Listarray as $entry) { echo "$entry"; } But it only list one array element(1 list). Does anyone have an idea on how to list a whole array? (I mean with a variable amount of inputs) Thanks in advance! Anzeo Quote Link to comment https://forums.phpfreaks.com/topic/67766-solved-listing-variables-in-an-array/ Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 Its pretty difficult to tell what you need, maybe this helps? <?php foreach($_POST['List'] as $list) { $entry = explode(',',$list); foreach($entry as $data) { echo $data."<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67766-solved-listing-variables-in-an-array/#findComment-340426 Share on other sites More sharing options...
Anzeo Posted September 3, 2007 Author Share Posted September 3, 2007 Hmm no, i'll try to explain my intentions a bit better. I want to create a simple form which would allow me to fill in a list in a textarea the list would be formatted like this: data1,data2,data3,etc... I then need all those data's to be listed so I can work with them seperatly (like inserting them into a DB). But I can't find out how to make a list (to use a foreach statement afterwards) which consits of an unknown variable amount of entries. Quote Link to comment https://forums.phpfreaks.com/topic/67766-solved-listing-variables-in-an-array/#findComment-340441 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Well when $entry gets exploded, it turns into an array of the information. For example when you explode the commas in data1,data2,data3 it returns with $entry[0] = data1 $entry[1] = data2 $entry[2] = data3 Or atleast I think so. Quote Link to comment https://forums.phpfreaks.com/topic/67766-solved-listing-variables-in-an-array/#findComment-340444 Share on other sites More sharing options...
trq Posted September 3, 2007 Share Posted September 3, 2007 All you need then is... <?php $entry = explode(',',$_POST['list']); foreach($entry as $data) { echo $data."<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67766-solved-listing-variables-in-an-array/#findComment-340445 Share on other sites More sharing options...
Anzeo Posted September 3, 2007 Author Share Posted September 3, 2007 Darn it, I can't believe how simple the answer was... Thanks alot for you help and time thorpe and Timma! Quote Link to comment https://forums.phpfreaks.com/topic/67766-solved-listing-variables-in-an-array/#findComment-340457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.