logo
down
shadow

How to compare 2 array of PHP objects then fill in empty string if data not match?


How to compare 2 array of PHP objects then fill in empty string if data not match?

Content Index :

How to compare 2 array of PHP objects then fill in empty string if data not match?
Tag : php , By : Cosmin
Date : January 12 2021, 07:00 PM

fixed the issue. Will look into that further There has 2 array with different size, the array need to filled in with empth string if data not match. , try this!
new_array= array();
foreach ($array_B as $key => $data) {
    $found = false;
    $cost = 0;
    for($i=0;$i<count($array_A);$i++){
        if($array_A[$i]['code']==$data['code']){
        $found = true;
        $cost = $array_A[$i]['cost'];
    }
}
// print_r($data);
if (!$found){
  $new_array[count($new_array)+1] = ['code'=>$data['code'], 'cost'=>$cost];
}else{
  $new_array[count($new_array)+1] = ['code'=>$data['code'], 'cost'=>$cost];
}
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

array of string fill of data in jquery but go empty to controller


Tag : javascript , By : sayuki288
Date : March 29 2020, 07:55 AM
help you fix your problem the problem is i pass string array from jquery to controller and when i use debugger in browser see the array full of data but when i but brake point in function in mvc controller the parameter arrive = null , Either do this
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
traditional: true,
data: { /* your data */ }.
contentType: 'application/json',
traditional: false,
data: JSON.stringify({ /* your data */ },

Using JavaScript to compare 2 arrays and create a new array of objects which does not contains the objects that match by


Tag : javascript , By : user150694
Date : March 29 2020, 07:55 AM
this one helps. Short and sweet. (Assumes one holds the first array and two holds the second array)
var oneIDs = one.map(function (a) {return a.id});

var result = two.filter(function (a) {
    return oneIDs.indexOf(a.id) === -1;
});

ReactJS - compare 3 objects based on length and fill the difference with empty field


Tag : javascript , By : Tom D
Date : March 29 2020, 07:55 AM
help you fix your problem I have 3 objects, each has a different length , Maybe something like this:
// Define max length
const maxLen = Math.max(obj1.length, obj2.length, obj3.length);

// Push missing itens for each arr object
obj1.push(...new Array(maxLen-obj1.length));
const arr = ... // your array of arrays
const maxLen = Math.max( ... arr.map(i => i.length));

arr.forEach( a => a.push(...new Array(maxLen-a.length));)

How to compare if, 2 separate Objects/Array have one same element and concat 2 objects into one array, if there is match


Tag : javascript , By : Lee KW
Date : March 29 2020, 07:55 AM
like below fixes the issue I have a promise.all that returns 2 objects. The common element in these 2 seperate objects is room. I want both object to be in 1 array, and if the room matches, I would like to concat the objects. , Here is my solution. Please try this code.
const mergedArray = patientObjArray.map(obj => {
    const matched = patientObservationsArray.find(obs => obs.observation.room === obj.room);
    if (!!matched) {
        return { ...obj, ...matched.observation, comment: matched.comment.value };
    } else {
        return obj;
    }
});

console.log(mergedArray);

How do I fill a string array with empty objects?


Tag : java , By : Igor Carron
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • How to deregister/dequeue jquery.sticky.js in Elementor (Pro)?
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • How to test authentication using Laravel Dusk?
  • PHP parse_str not getting all $_GET variables
  • Variable issues in php class
  • Get orders between dates in Codeigniter
  • Eloquent Special Chars Issue
  • Keeping leading zeros column Mysql
  • Current level navigation in Wordpress
  • Add a custom text to WooCommerce cart items if the product has a specific shipping class
  • Error connecting to CommissionJunction Token : [60] SSL certificate problem: unable to get local issuer certificate
  • How do I add a new key value pair to an object in PHP?
  • Http post request to php with dart
  • How to add a route in with blade into parameters of a component
  • How can i get the source of a 777 - CHMOD php file?
  • Convert 2010-04-16 16:30:00 to "Tomorrow Afternoon"
  • How can I hide a $_GET variable to be more secured in PHP?
  • Login to Gmail Inbox using Curl?
  • Upload Excel or CSV file to MySQL with PHP
  • Outlook Marking Email as Junk Email
  • Upload an image using class.upload.php via AJAX, display image in form using jQuery
  • mysql_connect() causes page to not display (WAMP)
  • How to limit a users uploaded image size using PHP
  • What's the difference whether or not to run PHP in safe mode?
  • Logging in to a website cURL
  • Using php to create a password system with chinese characters
  • PHP is not called properly in IE using set interval function in Javascript
  • How to read pdf, ppt, xl, doc files content into a string in php/python
  • php script for currency conversion
  • In PHP... best way to turn string representation of a folder structure into nested array
  • PayPal for Indian Rupees (INR) any solution
  • PHP Deployment to Live Server
  • Ideal Multi-Developer Lamp Stack?
  • How can I save an image from a file input field using PHP & MySQL?
  • Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in
  • Connecting to external MySQL DB from a web server not running MySQL
  • Is it possible to add custom fields to a Drupal taxonomy term?
  • PHP 6.0 - Roadmap?
  • jQuery wait for ajax call to be over before continuing
  • checkUnique function?
  • How to define an n-m relation in doctrine?
  • Sort the unsorted text file and rewrite to same text file in sorted order
  • Version control a content management system?
  • How can i run Single PHP File using apache-tomcat-6.0.18?
  • Array of objects is empty when I come to retrieve one from the array
  • PHP Library: Calculate a bounding box for a given lat/lng location
  • Good Wordpress Theme/plugin for showing off code examples and scripts
  • Replace all spaces and special symbols with dash in URL using PHP language
  • globally get any field value in user table of logged in user
  • Can you get a job if you know XHTML, CSS and Basic PHP?
  • HTML Upload Form will only upload files found in the directory of the PHP file
  • Determine if a PHP array uses keys or indices
  • Are frameworks really necessary for beginners/intermediates?
  • PHP File Downloading Questions
  • Who owns a php exec tar extracted file?
  • Best way to get timezone of user based on area code
  • Mysql BETWEEN clause being ignored. No syntax error
  • Zend Framework: Getting request object in bootstrap
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com