work_it_work Posted December 2, 2012 Share Posted December 2, 2012 i have an website (shopping-cart) and i want to modify the invoice to show the VAT (tax) . right now if i enable vat tax the prices are shown incorrectly. if the price added by admin is 1000$ the total price with vat is 1200$ i want the price to be displayed 1000$ and before total i want to display the vat of the invoice example: if the total is 1000 the vat shown will be 1000 / 20 * 120 which means 166.66. so the invoice looks like this: product a qty1 price 1000 subtotal 1000 vat(tax) 166 total to pay 1000 in the template file i have this function which generates the total and subtotal: <table id="total"> <?php foreach ($totals as $total) { ?> <tr> <td class="right"><b><?php echo $total['title']; ?>:</b></td> <td class="right"><?php echo $total['text']; ?></td> </tr> <?php } ?> </table> using print_r($totals) will print: Array ( [0] => Array ( [code] => sub_total [title] => Sub-Total [text] => 1000.00€ [value] => 1000 [sort_order] => 1 ) [1] => Array ( [code] => total [title] => Total [text] => 1000.00€ [value] => 1000 [sort_order] => 9 ) ) using print_r($total) will print: Array ( [code] => total [title] => Total [text] => 202.00€ [value] => 202 [sort_order] => 9 ) basically it's simple what i want to do $totals array i must insert a new row inside to make it look like this: Array ( [0] => Array ( [code] => sub_total [title] => Sub-Total [text] => 1000.00€ [value] => 1000 [sort_order] => 1 ) [1] => Array ( [code] => VAT [title] => VAT [text] => 166.66€ [value] => 166.66[sort_order] => 2 ) [2] => Array ( [code] => total [title] => Total [text] => 1000.00€ [value] => 1000 [sort_order] => 9 ) ) how can i explode and add a row in the middle of the array? please help, thank you! Link to comment https://forums.phpfreaks.com/topic/271485-array-issue-need-to-insert-new-array-data-please-help/ Share on other sites More sharing options...
us2rn4m2 Posted December 2, 2012 Share Posted December 2, 2012 Ok, I don't know if I really understand, so I give you a little example how to add a key in the middle of an array echo '<pre>'; $a = array(0 => 'A', 1 => 'C'); echo 'BEFORE<br />'; print_r($a); array_splice($a, 1, 0, 'B'); echo 'AFTER<br />'; print_r($a); /* Result: BEFORE Array ( [0] => A [1] => C ) AFTER Array ( [0] => A [1] => B [2] => C ) */ Link to comment https://forums.phpfreaks.com/topic/271485-array-issue-need-to-insert-new-array-data-please-help/#findComment-1396959 Share on other sites More sharing options...
work_it_work Posted December 2, 2012 Author Share Posted December 2, 2012 thanks for your reply, i managed to solve this problem, here's the solution: $vat= array(array('code' => 'iva', 'title' => 'IVA', 'text' => $total1, 'value' => '123', 'sort_order' => '2')); array_splice($totals, 2, 0, $vat); <table id="total"> <?php foreach ($totals as $total) { ?> <tr> <td class="right"><b><?php echo $total['title']; ?>:</b></td> <td class="right"><?php echo $total['text']; ?></td> </tr> <?php } ?> </table> Link to comment https://forums.phpfreaks.com/topic/271485-array-issue-need-to-insert-new-array-data-please-help/#findComment-1396964 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.