I have an array of arrays and wish to put the data in a specific order.
Here is my html form. The user(s) can add new rows to input more data as necessary.
<tr>
<td><input type="text" value="" placeholder="Date of Transfer" name="date[]"/></td>
<td><input type="text" value="" placeholder="Equpment Tag" name="tag[]"/></td>
<td><input type="text" value="" placeholder="Equpment Model" name="model[]"/></td>
<td><input type="text" value="" placeholder="Current Room" name="oldRoom[]"/></td>
<td><input type="text" value="" placeholder="Current Owner" name="oldOwner[]"/></td>
<td><input type="text" value="" placeholder="Current Dept" name="oldDept[]"/></td>
<td><input type="text" value="" placeholder="New Room" name="newRoom[]"/></td>
<td><input type="text" value="" placeholder="New Owner" name="newOwner[]"/></td>
<td><input type="text" value="" placeholder="New Dept" name="newDept[]"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3"><a href="javascript:void(0);" id='anc_add'>Add Row</a></td>
<td colspan="3"><a href="javascript:void(0);" id='anc_rem'>Remove Row</a></td>
<td colspan="3"><button type="submit">Submit</button></td>
</tr>
Then I'm putting the $_POSTed values into the $data array variable.
$data = array( tag => $_POST['tag'],
model => $_POST['model'],
oldRoom => $_POST['oldRoom'],
oldOwner => $_POST['oldOwner'],
oldDept => $_POST['oldDept'],
newRoom => $_POST['newRoom'],
newOwner => $_POST['newOwner'],
newDept => $_POST['newDept']
);
I figured out how to get the result i wanted manually getting the values of the $data array, but want to loop though all the data.
//manual retreaval
echo "</br></br>Manually getting data from the $data array</br>";
echo $data['tag'][0] . " - " . $data['model'][0] . " - " . $data['oldRoom'][0];
outputs:
tag1 - model1 - oldRoom1
So is there and how can I write a php script to loop though the $data array in the format as seen above?
tag1 - model1 - oldRoom1 - .... tag2 - model2 - oldRoom2 - ...