473,614 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to compare two arrays and find the count of match elements

semanticnotion
66 New Member
Hello all, i have two arrays i.e
Expand|Select|Wrap|Line Numbers
  1. $ar1=array("Mobile","shop","software","hardware");
and
Expand|Select|Wrap|Line Numbers
  1. $arr2=arry("shop","Mobile","shop","software","shop")
i want to compare the elements of arr2 to arr1 i.e
Expand|Select|Wrap|Line Numbers
  1. foreach($arr2 as $val)
  2.     { 
  3.         if(in_array($val, $arr1))
  4.         {    
  5.             //mycode to insert data into mysql table
  6.  
  7.             variable++;  // here there should be a variable that must be increamented when ever match found in $arr2 so that it can be saved into another table.
  8.         }
  9.          $query="update table set shop='$variable',Mobile='$variable'.......";
  10.      }
my problem is when ever a match is found in if(in_array($va l, $arr1) my code will be executed. here i want a variable or an array to count how many times that matched item/element is found i.e for shop=3 and for mobile and software it should be 1. Later in my update query i want to set the fields with this count
Mar 28 '11 #1
1 3264
dgreenhouse
250 Recognized Expert Contributor
Try array_count_val ues()
see: http://php.net/manual/en/function.ar...unt-values.php
Mar 28 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
5446
by: Christopher Parent | last post by:
I have perused through the groups and a couple C++ manuals and haven't been able to figure this one out. Maybe I'm staring at it too much. Here's the setup, I have 2 files. One is a library and one is the program source: MyLibrary.C ----------- int InstallSigHandler( void (*sigHandler) (int) ) {
3
21320
by: Lance | last post by:
What is the fastest way to determine if two arrays that contain ValueTypes are equal? For example, lets say I have the following: Dim pt1 as New Drawing.Point(1, 2) Dim pt2 as New Drawing.Point(2, 3) Dim pt3 as New Drawing.Point(3, 4) Dim pt4 as New Drawing.Point(4, 5) Dim A() as Drawing.Point = {pt1, pt2, pt3}
1
2025
by: Jacob Thastrup | last post by:
Hi is there an easy way to compare arrays without going through each entry in the arrays? Say I have two arrays and I want to find entries that are not present in both. Thanks Jacob Thastrup
8
3394
by: Turbot | last post by:
Hello, Anyone know how to compare two byte arrays without going through each item in the array. I actually want to compare two bitmap objects to see if they both contain the same picture bit have been unable to do this. I figured if I converted them to byte arrays there would be a simple way of comparing them but I have had no luck. Thanks in advance.
2
4098
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific table in my database. Here is the tables definition: Column | Type | Modifiers -------------------+------------------------+---------------------------------------------------- self | datagraph."GOLink" | not null default
3
1622
by: skosmicki | last post by:
I need to create an function similar to the "MATCH" function in Excel that evaluates a number within a set of numbers and returns whether there is a match. I have put the example of what I see in excel in the check column. The "0" answer in the result column is in the fourth account in the list. Somehow I need to loop through the accounts comparing the result to the total and indicate a match in the check column. It wouldn't even need...
1
1784
by: naqqash | last post by:
HI I am a beginner i VB please someone tell me how to compare values in array for exmple i've created an array for 10 day temperature now i want to know the maximum and minimum temperature in these 10 days what will be the way plzzzzzzzzzzzzzz help!!!!
2
5885
by: Sejoro | last post by:
Hello, I am trying to write a program that opens a file; reads through it; outputs the text; then outputs the number of lines, words, and characters. Problem is, every time I try to compile, no matter what modifications I make, I get an error, "line 42: Error: Could not find a match for std::basic_istream<char, std::char_traits<char>>::get(int)." I have tried everything I can think of. Help? #include <iostream> #include <fstream>
4
1690
by: clrockwell | last post by:
Hey all, I could use some help with solving problem. Any suggestions are welcome and very appreciated. I have two arrays, $feeds and $feedDays. If they both have the same count, or $feeds has only one value than there is not a problem. In this situation
9
24567
by: capablanca | last post by:
How can I compare arrays to see if they are equal, they have the same amount of elements for example: array = {{2,4,5,7,8},{1,3,5,7,8},{3,4,5,7,8}, {4,6,7,8,9},{2,4,5,7,8}};
0
8198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.