flemingmike Posted October 27, 2010 Share Posted October 27, 2010 hello all, i am having a for each problem. im trying to get two post fields using the foreach function. here is what i have in my form.php: <?php foreach($_POST['staff'] as $value) { echo "$value - <br />"; } ?> the name of the the fields coming in are name='staff[]' and the second one is name='descr[]' fields += 1; Quote Link to comment Share on other sites More sharing options...
flemingmike Posted October 27, 2010 Author Share Posted October 27, 2010 it is displaying each result for $_POST['staff'], i just cant figure out how to get it to also give me output for $_POST['descr'] Quote Link to comment Share on other sites More sharing options...
flemingmike Posted October 27, 2010 Author Share Posted October 27, 2010 if i do it this way, it gives me the wrong output <?php foreach($_POST['staff'] as $value) { foreach($_POST['staffd'] as $value1) { echo "$value - $value1<br />"; } } ?> Quote Link to comment Share on other sites More sharing options...
rwwd Posted October 27, 2010 Share Posted October 27, 2010 first see what's actually available in the $_POST array.. The way as you are doing it suggests as you are trying to get the data from a multidimensional array.. Rw Quote Link to comment Share on other sites More sharing options...
akitchin Posted October 27, 2010 Share Posted October 27, 2010 if you're trying to access the same index from the $_POST['descr'] array, you'll actually need to grab the index from the $_POST['staff'] array in your foreach(): foreach ($_POST['staff'] AS $key => $val) { echo 'Staff: '.$value.'<br />'; echo 'Description: '.$_POST['descr'][$key].'<br />'; } Quote Link to comment Share on other sites More sharing options...
flemingmike Posted October 27, 2010 Author Share Posted October 27, 2010 cool.. i had to modify slightly, but thanks for that! <?php foreach ($_POST['staff'] AS $key => $val) { echo 'Staff: '.$_POST['staff'][$key].'<br />'; echo 'Description: '.$_POST['staffd'][$key].'<br />'; } ?> Quote Link to comment 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.