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

  • SEARCH
  • Home
  • 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 7760943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:01:31+00:00 2026-06-01T14:01:31+00:00

I am trying to do something that’s quite complex (for me anyway) and I’ve

  • 0

I am trying to do something that’s quite complex (for me anyway) and I’ve got a point which has stopped me in my tracks.

In this project, you enter the weight of a box, and the percentage of materials held in that box. So for example, a box may have 10% of wood, 40% of plastic, and 50% of paper. The weights of the materials are held in the database as they dont change. So the value of 1% of wood is held in the database, as 1% of plastic and paper.

The controller should then take the percentage of material given, and then multiply it by the 1% value held in the database.

So far, this is my code:

foreach($wastestream as $ws) { 
        $genweight = $ws['Materialtype']['1pc'] * $ws['Valuegiven']['percent'];
}

And this gives the following values:

10% Wood = 97.5
40% Plastic = 100.4
50% Paper = 40.3

The problem I now have is that I have to add all of these variables together. So essentially what I want to do after it pumps out the values is to add them all up together, so:

97.5 + 100.4 + 40.3 = 238.2

What should I do?

Cheers!

  • 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-06-01T14:01:32+00:00Added an answer on June 1, 2026 at 2:01 pm

    I think I have misunderstood something, since it seems not complicated at all…

    $total=0;
    foreach($wastestream as $ws) { 
            $total += $ws['Materialtype']['1pc'] * $ws['Valuegiven']['percent'];
    }
    

    $total will hold the total value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do something that has been done many times before by
I'm trying to create something that works like this but doesn't have any submenus.
I am trying to setup something that looks like this with the arrow that
I'm still learning what hibernate can do and this time i'm trying something that
Im trying to do something that I originally thought would be quite simple, but
I'm trying to write something that has a callback function for a webkitTransitionEnd eventListener,
Im trying to create something that looks like this using php gd library: I've
I'm trying to achieve something that seems quite simple but I have hard time
I'm trying to do something that should be very simple, but it's causing this
I am trying to implement something that requires a structure like this: struct abc

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.