Question: how to get last data from foreach , i want to save for last data to result , 

image for result :

**Result**

[![enter image description here](https://i.stack.imgur.com/4gENH.jpg)](https://i.stack.imgur.com/4gENH.jpg)

```
<?php
$s_kredit   = 0;
foreach ($ju as $j ) {
                $s_debet += $j->debet   - $j->kredit;
                $s_kredit += $j->kredit - $j->debet;
<tr>
<td class="center"><?php if(@$set_saldo->debet==0) { echo "-"; } else { echo number_format($s_debet,0,".","."); } ;?></td>
<td class="center"><?php if(@$set_saldo->kredit==0) { echo "-"; } else { echo number_format($s_kredit,0,".","."); } ;?></td>
</tr>

```

Answer: 
```
<?php 
$data=array(1,3,4,5,6,7,7);
$last = $data[count($data) - 1]; 
?>

```
```
<?php
// ok try it nothing else, every loop change $last value, & when loop end, last variable will stored in the $last. 
$s_kredit   = 0;
$last = '';
foreach ($ju as $j ) {
            $s_debet += $j->debet   - $j->kredit;
            $s_kredit += $j->kredit - $j->debet;
            $last = $j;
<tr>
<td class="center"><?php if(@$set_saldo->debet==0) { echo "-"; } else { echo    number_format($s_debet,0,".","."); } ;?></td>
<td class="center"><?php if(@$set_saldo->kredit==0) { echo "-"; } else {    echo number_format($s_kredit,0,".","."); } ;?></td>
</tr>

```