Am spliting file string into array by using fgets(),and explode()
On other hand am taking string from user,and again spliting it into array
now I have 2 array
when I compare 2 arrays by using array_intersect()(even by using 2 foreach(as a last try))...it is returning null array(Array()) even if they have common elements
WHY?
is any special settings/parameter/syntax require to compare file data with normal array?
12 1859
Let us see a portion of both arrays
do u need to find common elements in 2 arrays ?
u can loop through the bigger one.. "use count() to find which one is bigger"
then use in_array() function and if condition inside the loop to find if each element in big array is already exist in other array..
inside if cindition u can add this common elements in third array if u want like this -
-
if(in_array($big_array[$i] , $small_array))
-
{
-
$common_array[] = $big_array[$i];
-
}
-
-
hope this helps.
he says array_intersect give 'em null array.
this may let him analyse why he get null array easly..
Outputting the arrays to ensure that there actually ARE matching elements will help him analyze why he is getting an empty array, not running the same code in a different format.
FOR ME, my method makes me feel comfortable while seeing every thing is running step by step.
Which would make sense if your code showed the user everything, step by step. - foreach ($array1 as $array1_data) {
-
echo "Array 1 data, '$array1_data', "
-
. (in_array($array1_data, $array2) ? 'is' : '<b>is not</b>')
-
. " in Array 2.<br />\n";
-
}
xD
u have wrote a code specialized in showing which elements in common, outputing on screen.
main goal is common element array.
Right, which is the exact goal of array_intersect(). If the OP is not getting the correct results from array_intersect(), then they won't get the correct results from your remake, either.
u know break points ?
mine makes me able to make something like that in my mind, which is not provided in array_intersect().
I don't even use breakpoints while programming or debugging. I doubt the OP does.
and does too for question poster.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: davehunt |
last post by:
Hi folks,
New C# programmer here.
I am reading some CSV data from a file into an ArrayList. I want to get the
data from the ArrayList into a 2-dimensional array. I see a few references to...
|
by: yourmycaffiene |
last post by:
Okay, this if my first post so go easy on me plus I've only been using
C for a couple of weeks. I'm working on a program currently that
requires me to read data from a .dat file into a 2d array and...
|
by: becca0619 |
last post by:
Hey, Ive been looking around to find out how to read data into a 2D array and I cant find a solution that will fit my assignment. Im not sure that I should even use an array actually...
ok so...
|
by: Frank Rizzo |
last post by:
I've had a windows service, that I've written and compiled with vs2003
and .net framework 1.1, running just fine on windows server 2003 for a
long while. Recently the service was installed on...
|
by: wartech |
last post by:
Hey everyone,
My objective here is to be able to sort the array that i created from a structure. When I attempt to do this I get a message stating "Failed to compare two elements in the array". ...
|
by: runsun |
last post by:
Thanks in advance. This program is written in C.
It needs to read all characters from a file; then write them into a 3D array (yes, 3D!).
The file is a .prn file (one of the Excel types), which...
|
by: BobbyS |
last post by:
I've a xml file.I'm taking its data passing it to a method in string form and converting that string "xmlData" to a array of bytes by Convert.FromBase64String(xmlData) but I'm getting a exception...
|
by: Amzul |
last post by:
hello all,
i have a roblam that need some new view.
i have a file that contain ip | country
what i am tring to do is to know how many ips i have from each country.
the file looks like...
|
by: wesley1970 |
last post by:
<?php
$a = array(1,2,3,4,5);
$b = array(1,2,3,4,5,6,7,8);
echo array_intersect($a, $b);
?>
array_intersect should return the numbers of items intersect in 2 arrays. In this case, it...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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,...
| |