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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:09:37+00:00 2026-05-12T07:09:37+00:00

I have two indexed arrays $measurements[] and $diffs[] , $measurements[] is filled with values

  • 0

I have two indexed arrays $measurements[] and $diffs[] ,

$measurements[] is filled with values from a database and the $diffs[] gets values from a function which calculates the difference from two measurements.

When I have a collection of different measurements in $measurements[] I want to add a value to just one array element in the $diffs[] array and then loop through it, then where the array element got updated check for corresponding index array element in the $measurements[] array en deduct it from there.

What I’m trying to accomplish is to have a specific difference deducted from a corresponding measurement when I have a collection of measurments.

Is this possible in php and how would I go about doing this.

Edit: to make it more descriptive (english is not my first language nor is php)

$measurements Array ( [0] => 1469 [1] => 1465 [2] => 739 [3] => 849 ) 

$diffs Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) 

I would like to update $diffs array index [2] => 200 so it becomes

Array ( [0] => 0 [1] => 0 [2] => 200 [3] => 0 )

and then subtract $diffs array index [2] from $measurements array index [2] in this case 739 – 200

I sincerely hope this makes it more clear.

  • 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-12T07:09:37+00:00Added an answer on May 12, 2026 at 7:09 am

    I’m sure it’s possible… it sounds like you need just a few foreaches and some basic arithmetic.

    But more specific than that, I can’t help you. I can’t understand your description of the problem.


    Edit: Now, with more information on the table, the code isn’t all that complex. Here’s how I would do it:

    foreach ($measurements as $index => $measurement) {
      $measurements[$index] -= $diffs[$index]; // subtract the negative difference from the measurement.
      unset($diffs[$index]);           // clear the modifier after use.
    }
    

    This code iterates through each element in the $measurements array, and subtracts a number from the corresponding index in $diffs. This code doesn’t require that $diffs has matching size with $measurements, because PHP will coerce a missing index-value to zero.

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

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have two arrays which I want to join together. I want to preserve
I have a function which is passed two structures by reference. These structures are
I have an object that contains two arrays, the first is a slope array:
I have two arrays that I need to sort A->Z but all numerical indexes
im trying to merge two arrays together. both have numeric keys and are unique.
I have two arrays: var columns = ["Date", "Number", "Size", "Location", "Age"]; var rows
I have two arrays, each containing strings. The first array is a list of
Here I have written code for finding median of two sorted arrays: #include<iostream> using
I have two arrays. One for input boxes and other for checkbox. inputbox[] checkbox[]

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.