Search code examples
phppdf-generationforeach-loop-container

how to save foreach loop last value into variable


How can i store last value of $total['value'] into $COD?

Variable and echo it and other place of page code is

 <?php foreach( $wpo_wcpdf->get_woocommerce_totals() as $key => $total ) : ?>
    <tr class="<?php echo $key; ?>">
        <td class="no-borders">&nbsp;</td>
        <th class="description"><?php echo $total['label']; ?></th>
        <td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>
    </tr>   
<?php endforeach; ?>

This code of "WooCommerce PDF Invoices & Packing Slips" free plugin


Solution

  • Try this, values will get overwritten and ultimately you will have last value

    $COD = $total['value'];