Yeah, using arrays would be better. My suggestion was with the assumption that you have no control over the format of the form element names.
However, if you are going to use arrays, then I suggest that you group them instead of having parallel arrays, e.g.,
<input type="text" size="15" name="ciw[1][name]" placeholder="Name"> <input type="text" size="25" name="ciw[1][url]" placeholder="URL"> $<input type="text" size="5" name="ciw[1][price]" placeholder="Price"><br>
<input type="text" size="15" name="ciw[2][name]" placeholder="Name"> <input type="text" size="25" name="ciw[2][url]" placeholder="URL"> $<input type="text" size="5" name="ciw[2][price]" placeholder="Price"><br>
<input type="text" size="15" name="ciw[3][name]" placeholder="Name"> <input type="text" size="25" name="ciw[3][url]" placeholder="URL"> $<input type="text" size="5" name="ciw[3][price]" placeholder="Price"><br>
<input type="text" size="15" name="ciw[4][name]" placeholder="Name"> <input type="text" size="25" name="ciw[4][url]" placeholder="URL"> $<input type="text" size="5" name="ciw[4][price]" placeholder="Price"><br>
<input type="text" size="15" name="ciw[5][name]" placeholder="Name"> <input type="text" size="25" name="ciw[5][url]" placeholder="URL"> $<input type="text" size="5" name="ciw[5][price]" placeholder="Price"><br>
This way, you have a single array with the data, i.e., $POST['ciw']. That said, note that even with this, you cannot assume that just because $POST['ciw'][1]['name'] is not empty that $_POST['ciw'][1]['price'] exists: you should still check with isset or empty or check the key against the array, and validate your incoming data.
EDIT:
schwim wrote:$sub_ciw_name, url and price are showing as undefined, so I think I've messed up here somehow:
Yes, you have. You should be accessing $POST['ciw_name-1'], etc. Therefore:
for ($i = 1; $i <= 20; $i++) {
$ciw_name = sprintf('ciw_name-%d', $i);
$ciw_url = sprintf('ciw_url-%d', $i);
$ciw_price = sprintf('ciw_price-%d', $i);
if (isset($_POST[$ciw_name], $_POST[$ciw_url], $_POST[$ciw_price])) {
// ...
} else {
break; // ?
}
}