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 7839197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:22:06+00:00 2026-06-02T15:22:06+00:00

Lets say I’ve got an array: Array ( [0] => Array ( [filmType] =>

  • 0

Lets say I’ve got an array:

Array
(
    [0] => Array
        (
            [filmType] =>  Symphony 15%
            [rollSize] => 36
            [linearFt] => 3
        )

    [1] => Array
        (
            [filmType] =>  Symphony 15%
            [rollSize] => 36
            [linearFt] => 3
        )
    [2] => Array
        (
            [filmType] =>  Symphony 15%
            [rollSize] => 48
            [linearFt] => 5
        )

    [3] => Array
        (
            [filmType] =>  Symphony 25%
            [rollSize] => 36
            [linearFt] => 7
        )
    [4] => Array
        (
            [filmType] =>  Symphony 35%
            [rollSize] => 36
            [linearFt] => 10
        )
    [5] => Array
        (
            [filmType] =>  Symphony 35%
            [rollSize] => 36
            [linearFt] => 10
        )

How is it possible to add up the [linearFt] of ONLY unique array elements. By unique I mean [filmtype] and [rollSize] the same.

I have tried multible ways including searching array, array filter, and usort… I am new to PHP and this is NOT homework. Thanks for any help!

So my output would be:

$totalsArray = Array(

    [0] => Array
        (
            [filmType] =>  Symphony 15%
            [rollSize] => 36
            [linearFt] => 8
        )

    [1] => Array
        (
            [filmType] =>  Symphony 15%
            [rollSize] => 48
            [linearFt] => 3
        )
    [2] => Array
        (
            [filmType] =>  Symphony 25%
            [rollSize] => 48
            [linearFt] => 7
        )
    [3] => Array
        (
            [filmType] =>  Symphony 35%
            [rollSize] => 48
            [linearFt] => 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-06-02T15:22:09+00:00Added an answer on June 2, 2026 at 3:22 pm

    Ah. I would attack this with a foreach loop to get each array, then accumulate the different types and sizes and add them as I go. It would look like this:

    $filmTotals = array();
    $filmTemp   = array();
    foreach ($filmInventory as $film){
        $filmTemp[$film['filmType']][$film['rollSize']] = $filmTemp[$film['filmType']][$film['rollSize']] + $film['linearFt'];
    }
    
    // A second foreach to resort into the final format, nested to get the keys out to rename them correctly
    foreach ($filmTemp as $filmType=>$film){
        foreach ($film as $filmSize=>$filmLength){
            $filmTotals[] = array('filmType'=>$filmType, 'rollSize'=>$filmSize, 'linearFt'=>$filmLength);
        } //END inner foreach
    } // END outer foreach
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I've got two interchangeable pieces of code and I want to figure
Lets say I have an array like this: string [] Filelist = ... I
Lets say I am currently at: http://example.com/folder/page.html Is it possible to create a relative
Lets say I have an array of javascript objects, and I am trying to
Lets say i got this div <div> Convert This into a vertical Text </div>
Lets say I have View1 and it's got BreakfastID, Eggs, Toast for it's columns
Lets say we've got a Grid with with 30 columns and 30 rows. Rules
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say I have a loop in Bash: for foo in `some-command` do do-something
Lets say I have multiple DataGrids throughout my winform app and I want to

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.