I have a foreach that iterates between items in a array to build an excel file.
I want to place a total row after each item in the array if the next element in the array matches a specific condition (has a specific value in one key).
So I want to use next()
to check that value but as far as I know and for what I read here using next I'll move the pointer to the next row and the answer was to use current. How can I see the next item in the array without moving the pointer? reading that question I have written this:
foreach($creds as $cred){
echo $cred['tipo'];
//if the next item has a 'tipo' key with a specific value
if(current($creds['tipo'])!='4'){
echo 'Total';
}
}
but this is not working. How to fix it?
EDIT: based on the answers I will move the echo 'Total' stuff at the beginning of the next iteration instead of at the bottom of the current iteration. There are no other solutions using foreach as far as I see in the answers