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; Link to comment https://forums.phpfreaks.com/topic/217039-for-each-question/ 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'] Link to comment https://forums.phpfreaks.com/topic/217039-for-each-question/#findComment-1127246 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 />"; } } ?> Link to comment https://forums.phpfreaks.com/topic/217039-for-each-question/#findComment-1127253 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 Link to comment https://forums.phpfreaks.com/topic/217039-for-each-question/#findComment-1127257 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 />'; } Link to comment https://forums.phpfreaks.com/topic/217039-for-each-question/#findComment-1127260 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/217039-for-each-question/#findComment-1127263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.