inspireddesign Posted November 18, 2010 Share Posted November 18, 2010 Hello all, I think I have a simple question. I have several arrays that I need the output from but I need the output from each array to be together. I know WHAT?! I'll try to explain: I have a dynamic jQuery form that fills in a table with data. Each "field" or <td> has separate information in each. The way I output the data is in an input box so that I can capture the value of each. The name attribute is the array for each input. So for example the output for each would look like this: <tr> <td> <input type="text" name="fullName[]" value="input_from_user"/> </td> <td> <input type="text" name="Address[]" value="input_from_user"/> </td> </tr> If you can visualizes this we could have several rows of data from each array (fullName[] and Address[]). How would I extract the data in such a way that I can clump them into their appropriate rows? I know how to extract them one by one using foreach loop on each array but that won't do what I want. I would like the output to be like this: John Doe - 22 S Main Street Jim Smith - 111 N Main Street and so on... This is what I have so far but I'm sure this isn't how to accomplish what I'm after. $name = $_POST['fullName']; $address = $_POST['Address']; $outputArry = array( "FullName" => $name, "Address" => $address ); foreach ( $outputArry as $output ) { foreach ( $output as $row ) { $rowFullName = $row['FullName']; $rowAddress = $row['Address']; $rowOutput .= 'Name: ' . $rowFullName . ' Address: ' . $rowAddress . '<br />'; } } echo $rowOutput; Thanks for any help on this issue. Damian Quote Link to comment https://forums.phpfreaks.com/topic/219103-array-problem/ Share on other sites More sharing options...
BlueSkyIS Posted November 18, 2010 Share Posted November 18, 2010 This is what I have so far but I'm sure this isn't how to accomplish what I'm after. did you run the code to check and see? any errors, incorrect output? Quote Link to comment https://forums.phpfreaks.com/topic/219103-array-problem/#findComment-1136181 Share on other sites More sharing options...
inspireddesign Posted November 18, 2010 Author Share Posted November 18, 2010 Yeah, the output is only showing the first character of the array and it's not looping correctly: Here's the output: FYI: I only have two rows of data. So the output below in incorrect. There should only be two rows not four. Name: D Address: D Name: T Address: T Name: 4 Address: 4 Name: 3 Address: 3 Also, I've moved the $rowOutput var in the first loop which did only give me two rows but the output was also not correct. Here's that output: Name: T DOB: T Name: 3 DOB: 3 Damian Quote Link to comment https://forums.phpfreaks.com/topic/219103-array-problem/#findComment-1136219 Share on other sites More sharing options...
seanlim Posted November 18, 2010 Share Posted November 18, 2010 $output = ""; foreach($_POST['fullName'] as $k=>$v){ $output .= "Name: ".$v." Address: ".$_POST['Address'][$k]."<br>"; } echo $output; Quote Link to comment https://forums.phpfreaks.com/topic/219103-array-problem/#findComment-1136247 Share on other sites More sharing options...
AbraCadaver Posted November 18, 2010 Share Posted November 18, 2010 Or: foreach(array_combine($_POST['fullName'], $_POST['Address']) as $name => $address) { echo "$name - $address"; } Quote Link to comment https://forums.phpfreaks.com/topic/219103-array-problem/#findComment-1136276 Share on other sites More sharing options...
inspireddesign Posted November 18, 2010 Author Share Posted November 18, 2010 Both solutions worked great! Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/219103-array-problem/#findComment-1136376 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.