There are two(2) scenarios when retrieving entries from the users.
- Scenario 1: User enters one(1) entry per person
- Scenario 2: User enters more than one(1) entry for either or both person(s)
Scenario 1:
User enters one(1) entry for each person.

var_dump() returns (correct)
array(
5
)
{
[0] => string(8) "John Doe"1 => string(6) "Apples"2 => string(2) "50"[3] => string(3) "200"[4] => string(10) "2015-01-16"
}
array(
5
)
{
[0] => string(8) "Jane Doe"1 => string(7) "Bananas"2 => string(2) "20"[3] => string(3) "100"[4] => string(10) "2015-01-16"
}
Scenario 2:
User enters more than one(1) entry for either or both person(s).

var_dump() returns (Incorrect)
array(
5
)
{
[0] => string(8) "John Doe"1 => string(6) "Apples"2 => string(2) "50"[3] => string(3) "200"[4] => string(10) "2015-01-16"
}
array(
5
)
{
[0] => string(8) "Jane Doe"1 => string(7) "Oranges"2 => string(2) "20"[3] => string(3) "100"[4] => string(10) "2015-01-16"
}
array(
5
)
{
[0] => NULL1 => string(7) "Bananas"2 => string(2) "20"[3] => string(3) "200"[4] => string(10) "2015-01-16"
}
The above dump shows the second entry with Jane Doe instead of John Doe and the entry for Jane Doe with a NULL name entry.
HTML Form
<div class="toclone">
<p class="name">
<input type="text" name="name[]" id="sname" placeholder="Name"/>
</p>
<div class="inner-wrap">
<!-- <strong>Procurement Information</strong> -->
<div class="clone-inner">
<p>
<input type="text" name="item[]" id="sitem" placeholder="Item"/>
<input type="text" name="quantity[]" id="sqty" placeholder="Quantity"/>
<input type="text" name="amount[]" id="samt" placeholder="Amount"/>
<input type="text" name="date[]" id="sdate" placeholder="Date"/>
<a href="#" class="phclone btn btn-xs btn-success"><i class="fa fa-plus fa-fw"></i></a>
<a href="#" class="phdelete btn btn-xs btn-danger"><i class="fa fa-times fa-fw"></i></a>
</p>
</div>
</div>
<a href="#" class="clone btn btn-xs btn-success"><i class="fa fa-plus fa-fw"></i> Add Name</a>
<a href="#" class="delete btn btn-xs btn-danger"><i class="fa fa-times fa-fw"></i> Delete Name</a>
</div>
<p class="submit">
<input type="submit" name="saveProcurement" value="Save" class="btn btn-sm btn-primary"/>
</p>
Controller
$name = $this->input->post('name');
$item = $this->input->post('item');
$quantity = $this->input->post('quantity');
$amount = $this->input->post('amount');
$date = $this->input->post('date');
$limit = array();
if (count($name) >= count($item)) {
$limit = $name;
} else {
$limit = $item;
}
for ($i = 0; $i < count($limit); $i++) {
var_dump(array($name[$i], $item[$i], $quantity[$i], $amount[$i], $date[$i]));
}
How do I modify the loop to allow both scenarios to work fine?
Any help is appreciated.