Try to search your question here, if you can't find : Ask Any Question Now ?

How do I get sum of all figures inside a string but for the whole column? figures are contained in messages as below

HomeCategory: stackoverflowHow do I get sum of all figures inside a string but for the whole column? figures are contained in messages as below
Avatarsourav asked 3 months ago
  • MEL1INFA73 Confirmed. Ksh29.00 sent to Safaricom Offers for account Tunukiwa on 21/5/18 at 3:29 AM New M-PESA balance is Ksh5.50. Transaction cost, Ksh0.00.
  • MEE6ESSVCS Confirmed. Ksh2,240.00 paid to Naivas West End Plaza. on 14/5/18 at 8:13 PM.New M-PESA balance is Ksh4,753.50. Transaction cost, Ksh0.00.
  • MEF1EZ0MNR Confirmed.You have received Ksh10,000.00 from Barclays Bank K LTD 303031 on 15/5/18 at 9:36 AM New M-PESA balance is Ksh14,775.50. Buy goods with M-PESA.

The following code generates sum of figures in each row other than the whole column, Thanks.

 <?php 
                if(count($json_data["data"]) > 0){ ?>
                    <?php $_count = 1;
                        foreach($json_data["data"] as $row){ ?>
                            <tr>
                                <td><?php 
                                $str =$row["msg_body"];
                                preg_match_all("/kshs*(d+.d+)/i", $str, $matches);
                                echo array_sum($matches[1]); ?></td>
                            </tr>
                    <?php $_count ++; }
                    ?>
            <?php }else{

                }
            ?></td>
1 Answers
Best Answer
AvatarFernando answered 3 months ago
Your Answer

0 + 18 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com