I have the below foreach loop
$i = 1;
$array = array();
foreach ($titles as $title){
if (empty($title) ){
echo "EMPTY " .$i ;
}else{
array_push($array, $_POST['miles'.$i.'1']);
}
$i++;
}
The line array_push($array, $_POST['miles'.$i.'1']);
should add to the array the value of $_POST['miles11']
on the first loop (so long as $title is not empty).
And then on the next loop value of $_POST['miles21']
etc. etc.
However this does not work as nothing actually gets added to the array just an empty item. I assume I do not have the syntax right for doing the above but I am not sure what is the correct way to do it.
Thank you
Examples
If all $titles are not empty the array looks like:
Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => )
If some are empty we get for example:
EMPTY 1EMPTY 3EMPTY 5EMPTY 7Array ( [0] => [1] => [2] => )