Compare only values of arrays and get difference

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have two arrays like below;

array1 =  {
           [0]=> 'A'
           [1]=> 'B'
           [2]=> 'C'
          }

array2 =  {
           [0]=> 'B'
           [1]=> 'C'
           [2]=> 'D'
          }

I want to compare these two arrays and get the difference. What I need return is like this;

result = { [0]=> 'A' [1]=> 'D' }
I thought I could use array_diff, but it compares key AND value as a pair. I want to compare ONLY values. How can I do that?

profilepic.png
manpreet 2 years ago

This should b.com/tag/work">work -

array_diff(array_merge($a, $b), array_intersect($a, $b))

Checking b.com/tag/difference">difference between all merged and all common.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.