Ok I have a foreach loop and wanted to know if I could get the last iteration data value for the current iteration?
Code:
foreach($array as $key=>$data) {
echo "Key: ".$key." Data: ".$data."<br />";
}
Results:
Key: 0 Data: 23244
Key: 0 Data: Program ID: 39-1-1499-1
Results I would like:
Key: 23244 Data: Program ID: 39-1-1499-1
is there a way to get the key on the current iteration as the data from the last?
Or something to that effect should work.
It’s worth noting though, that it’s probably better to fix the source of the issue (the array) so that it outputs in the correct format and you can use your original code rather than this workaround.