Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:02:58+00:00 2026-05-27T05:02:58+00:00

I am using php and have the following structure <?php if(!empty($bids)): ?> <?php foreach

  • 0

I am using php and have the following structure

<?php if(!empty($bids)): ?>
  <?php foreach ($bids as $bid):?>
     <tr>
         <td><?php if($bid['Bid']['debit'] > 0) : ?><?php echo $bid['Bid']['debit']; ?><?php else: ?>&nbsp;<?php endif; ?></td>
         <td><?php if($bid['Bid']['credit'] > 0) : ?><?php echo $bid['Bid']['credit']; ?><?php else: ?>&nbsp;<?php endif; ?></td>
     </tr>
  <?php endforeach; ?>
<?php endif;?>

Now i need to calculate the sum total in each case. I know its easy but not getting how to use loop within the foreach to calculate the total value. Please suggest how to do that loop.

If suppose for the first td sample output structrue is as like below, i need to add up all and just display 22 and not the array

0 2 0 20
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:02:59+00:00Added an answer on May 27, 2026 at 5:02 am

    Try with:

    <?php
    
    if(!empty($bids)) {
      $debitSum  = 0;
      $creditSum = 0;
    
      foreach ($bids as $bid) {
        $debit  = $bid['Bid']['debit'];
        $credit = $bid['Bid']['credit'];
    
        echo '<tr>';
        echo '<td>' . ( $debit > 0 ? $debit  : '&nbsp;' ) . '</td>';
        echo '<td>' . ( $credit> 0 ? $credit : '&nbsp;' ) . '</td>';
        echo '</tr>';
    
        $debitSum  += $debit;
        $creditSum += $credit;
      }
    
      echo '<tr style="font-weight: bold">';
      echo '<td>' . $debitSum . '</td>';
      echo '<td>' . $creditSum . '</td>';
      echo '</tr>';
    
    }
    ?>
    

    Edit:

    If $bid['Bid']['debit'] (or credit too) is a string value, then cast it to int value:

    $debit = (int) $bid['Bid']['debit'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Iirf v2.0 . I have the following directory structure: / /library /library/index.php
I have following data to save in database using php my data is :
I want the following functionality using php I have a csv file. Each file
I have the following text: We%27re%20proud%20to%20introduce%20the%20Amazing I'd like to remove the encoding using PHP,
On Windows using WAMPserver (Apache, MySQL, PHP) I have the following: //test.php if (!defined('LC_MESSAGES'))
I have the following url structure: http://localhost/sitename/views/www/page.php I would like for page.php to show
I have a legacy PHP application that uses the following URL structure /product_info.php?products_id=YYY where
I have a (custom) php framework that contains following structure: app |-classes |-settings core
I'm using mysql/php/apache . I have the following situation: 2 tables where I need
I have the following MySQL query, which I'm using with PHP (5.2). DELETE t1.*,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.