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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:03:10+00:00 2026-05-28T01:03:10+00:00

I have searched and found nothing on this. I would like some advice or

  • 0

I have searched and found nothing on this.

I would like some advice or pointers on how I could search a multi dimensional array and update if a value exists or insert if it doesn’t exist.

Eg. at the moment I create an array with these values like this:

Array
(
[0] => Array
    (
        [quantity] => 1
        [supplier_paypal] => paypalaccount1@paypal.com
        [supplier_price] => 10
    )

[1] => Array
    (
        [quantity] => 2
        [supplier_paypal] =>  paypalaccount2@paypal.com
        [supplier_price] => 20
    )

    )

Now this is great but it just loops though and can create duplicate email addresses in the array. I need something that I can put in the loop that searches to see if the email exists and if it does then just merely adds the supplier prices together.

Any help or ideas?

Heres what I have tried:

 $arrIt = new RecursiveIteratorIterator(
 new RecursiveArrayIterator($this->data['payrecipient_data']));

foreach ($arrIt as $sub) {
$subArray = $arrIt->getSubIterator();
if ($subArray['supplier_paypal'] === $supplier_info['supplier_paypal']) {

    $this->data['payrecipient_dup'][] = iterator_to_array($subArray);
} else {
    $this->data['payrecipient_nondup'][] = iterator_to_array($subArray);
}
}

This just enabled me to search through and seperate the arrays into groups of duplicated and none duplicated.

But I don’t know where to start with updating an array so I got lost and stuck.

  • 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-28T01:03:10+00:00Added an answer on May 28, 2026 at 1:03 am
    $needle = 'foo@bar.com';
    
    $found = false;
    foreach ($array as &$element) {
        if ($element['supplier_paypal'] == $needle) {
            // update some data
            $element['foo'] = 'bar';
            $found = true;
            break;
        }
    }
    unset($element);
    
    if (!$found) {
        $array[] = array('supplier_paypal' => $needle, ...);
    }
    

    There are more elegant ways to index the data to find it quicker without looping through the whole thing every time, but this is essentially the basic algorithm you’re looking for.

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

Sidebar

Related Questions

I have searched all over for somebody else with this issue and found nothing...so
So i've searched and searched and I've found nothing like I'm looking. I have
I have searched on this problem, but have found nothing. I have triple checked
Sorry if this is a newbie question. I have searched but found nothing... Using
I have searched for a CGI and read about it but nothing useful found.
i have searched Xcode controls but doesn't found anything that makes a GridView like
I have searched and nothing that I have found hits directly on what I
I have searched for similar issues but I found nothing... I have a problem
I would like to convert a image query, found here http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=xxxxxxx&query=cars In vb2005.net to
I have searched far and wide for an answer to this question and would

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.