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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:41:45+00:00 2026-05-29T15:41:45+00:00

I have the following multidimensional array: Array ( [0] => Array ( [id] =>

  • 0

I have the following multidimensional array:

Array ( [0] => Array 
         ( [id] => 1 
           [name] => Jonah 
           [points] => 27 )
        [1] => Array 
         ( [id] => 2 
           [name] => Mark 
           [points] => 34 )
      )

I’m currently using a foreach loop to extract the values from the array:

foreach ($result as $key => $sub)
{
    ...
}

But I was wondering how do I see whether a value within the array already exists.

So for example if I wanted to add another set to the array, but the id is 1 (so the person is Jonah) and their score is 5, can I add the 5 to the already created array value in id 0 instead of creating a new array value?

So after the loop has finished the array will look like this:

Array ( [0] => Array 
         ( [id] => 1 
           [name] => Jonah 
           [points] => 32 )
        [1] => Array 
         ( [id] => 2 
           [name] => Mark 
           [points] => 34 )
      )
  • 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-29T15:41:46+00:00Added an answer on May 29, 2026 at 3:41 pm

    What about looping over your array, checking for each item if it’s id is the one you’re looking for ?

    $found = false;
    foreach ($your_array as $key => $data) {
        if ($data['id'] == $the_id_youre_lloking_for) {
            // The item has been found => add the new points to the existing ones
            $data['points'] += $the_number_of_points;
            $found = true;
            break; // no need to loop anymore, as we have found the item => exit the loop
        }
    }
    
    if ($found === false) {
        // The id you were looking for has not been found, 
        // which means the corresponding item is not already present in your array
        // => Add a new item to the array
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php multidimensional array populated from a table using the following code:
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
Let's assume I have the following multidimensional array (retrieved from MySQL or a service):
I have a multidimensional array with the following structure: teamMembers[teamMembers][0][Name]; teamMembers[teamMembers][0][Email]; teamMembers[teamMembers][1][Name]; teamMembers[teamMembers][1][Email]; etc.
I have two questions regarding the multidimensional arrays. I declared a 3D array using
I have the following two arrays: Array ( [Jonah] => 27 [Bianca] => 32
Quick Question: I have the following array (multidimensional): Array ( [preorder] => 0 [data]
I have a multidimensional array as follows: Array( [0] => Array ( [name] =>
I have the following multidimensional array: Array ( [0] => Array ( [area] =>
I have create following string multidimensional array in java. which has top outer array

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.