Re: [PHP] Array_diff problems

2012-04-27 Thread Rick Dwyer
Thanks to both for the direction.


 
 --Rick
On Apr 27, 2012, at 4:13 PM, Jim Giner wrote:

> 
> 
> Are these arrays nested in an array?  In that case the manual says you have 
> to do the compare differently.


On Apr 27, 2012, at 4:19 PM, admin wrote:

> 
> 
> -Original Message-
> From: Rick Dwyer [mailto:rpdw...@earthlink.net] 
> Sent: Friday, April 27, 2012 3:37 PM
> To: PHP-General
> Subject: [PHP] Array_diff problems
> 
> Hello all.
> 
> I have two arrays and when compared against each other via array_diff, I do
> not get any output:
> 
> $myarray1 = Array (
> [0] => Array ( [id] => 1 [Funding_Type] => Federal [Amount] => 10
> [Frequency_Description] => Total [Other_Funding] => ) [1] => Array ( [id] =>
> 2 [Funding_Type] => Trust [Amount] => 20 [Frequency_Description] => Per Year
> [Other_Funding] => ) [2] => Array ( [id] => 3 [Funding_Type] => Other
> Funding [Amount] => 30 [Frequency_Description] => Other [Other_Funding] =>
> some )) 
> 
> $myarray2 = Array
> (
> [0] => Array ( [id] => 1 [Funding_Type] => Federal [Amount] => 10
> [Frequency_Description] => Total [Other_Funding] => ) [1] => Array ( [id] =>
> 2 [Funding_Type] => Trust [Amount] => 20 [Frequency_Description] => Per Year
> [Other_Funding] => ) [2] => Array ( [id] => 3 [Funding_Type] => Other
> Funding [Amount] => 50 [Frequency_Description] => Other [Other_Funding] =>
> none )) 
> 
> $arraydifferences = (array_diff($myarray1,$myarray2));
> 
> I need $arraydifferences to record the differences between the two.
> 
> Any help is appreciated.
> 
> Thanks,
> 
> --Rick
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
> 
> 
> 
> I suggest you read Multidimensional array_diff for Nested Arrays and your
> format is not correct on the array that you gave an example of.
> 
> http://www.php.net/manual/en/function.array-diff.php#98680
> 
> 
> 
> 
> 
> 
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array_diff problems

2012-04-27 Thread admin


-Original Message-
From: Rick Dwyer [mailto:rpdw...@earthlink.net] 
Sent: Friday, April 27, 2012 3:37 PM
To: PHP-General
Subject: [PHP] Array_diff problems

Hello all.

I have two arrays and when compared against each other via array_diff, I do
not get any output:

$myarray1 = Array (
[0] => Array ( [id] => 1 [Funding_Type] => Federal [Amount] => 10
[Frequency_Description] => Total [Other_Funding] => ) [1] => Array ( [id] =>
2 [Funding_Type] => Trust [Amount] => 20 [Frequency_Description] => Per Year
[Other_Funding] => ) [2] => Array ( [id] => 3 [Funding_Type] => Other
Funding [Amount] => 30 [Frequency_Description] => Other [Other_Funding] =>
some )) 

$myarray2 = Array
(
[0] => Array ( [id] => 1 [Funding_Type] => Federal [Amount] => 10
[Frequency_Description] => Total [Other_Funding] => ) [1] => Array ( [id] =>
2 [Funding_Type] => Trust [Amount] => 20 [Frequency_Description] => Per Year
[Other_Funding] => ) [2] => Array ( [id] => 3 [Funding_Type] => Other
Funding [Amount] => 50 [Frequency_Description] => Other [Other_Funding] =>
none )) 

$arraydifferences = (array_diff($myarray1,$myarray2));

I need $arraydifferences to record the differences between the two.

Any help is appreciated.

Thanks,
 
 --Rick



--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php



I suggest you read Multidimensional array_diff for Nested Arrays and your
format is not correct on the array that you gave an example of.

http://www.php.net/manual/en/function.array-diff.php#98680





 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff()?

2008-06-25 Thread Wolf



Thiago H. Pojda wrote:

Ok, forget everything... it was just a user (programmer) problem..

while in translation process, labels_es became a copy of labels_pt :P

Sorry about the noise.

PS: Hoorray: again in list _o/

On Wed, Jun 25, 2008 at 5:24 PM, Thiago H. Pojda <[EMAIL PROTECTED]>
wrote:


I just hit tab and space at once and gmail just sent it ;)

Well, I'm not reaching that size, hehe.

Btw, PHP Version 5.2.6


On Wed, Jun 25, 2008 at 5:19 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:


On Wed, Jun 25, 2008 at 4:08 PM, Wolf <[EMAIL PROTECTED]> wrote:

So, where is your code that isn't working right?

Yeah, come on, Thiago, show code.  You know better than that!  ;-P

   And by the way, I *believe* that as long as your arrays are <=
65,355 entries - while it will be slow and may time out - it should
work.  So don't necessarily worry about "very long" arrays.



See, two programmer issues fixed in one day, your work is done, go home 
now!  ;)


And we learned a new quick sending technique for gmail.  How cool is that?

Playing with it, my array_diff was working fine, but I figured I had 
something screwed up somewhere.  ;)


Welcome back!


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff()?

2008-06-25 Thread Daniel Brown
On Wed, Jun 25, 2008 at 4:31 PM, Thiago H. Pojda <[EMAIL PROTECTED]> wrote:
>
> PS: Hoorray: again in list _o/

Yeah, I noticed your softpartech address was closed out.

-- 

Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff()?

2008-06-25 Thread Thiago H. Pojda
Ok, forget everything... it was just a user (programmer) problem..

while in translation process, labels_es became a copy of labels_pt :P

Sorry about the noise.

PS: Hoorray: again in list _o/

On Wed, Jun 25, 2008 at 5:24 PM, Thiago H. Pojda <[EMAIL PROTECTED]>
wrote:

> I just hit tab and space at once and gmail just sent it ;)
>
> Well, I'm not reaching that size, hehe.
>
> Btw, PHP Version 5.2.6
>
>
> On Wed, Jun 25, 2008 at 5:19 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:
>
>> On Wed, Jun 25, 2008 at 4:08 PM, Wolf <[EMAIL PROTECTED]> wrote:
>> >
>> > So, where is your code that isn't working right?
>>
>> Yeah, come on, Thiago, show code.  You know better than that!  ;-P
>>
>>And by the way, I *believe* that as long as your arrays are <=
>> 65,355 entries - while it will be slow and may time out - it should
>> work.  So don't necessarily worry about "very long" arrays.
>>
>> --
>> 
>> Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
>> $59.99/mo. with no contract!
>> Dedicated servers, VPS, and hosting from $2.50/mo.
>>
>
>
>
> --
> Thiago Henrique Pojda




-- 
Thiago Henrique Pojda


Re: [PHP] array_diff()?

2008-06-25 Thread Thiago H. Pojda
I just hit tab and space at once and gmail just sent it ;)

Well, I'm not reaching that size, hehe.

Btw, PHP Version 5.2.6

On Wed, Jun 25, 2008 at 5:19 PM, Daniel Brown <[EMAIL PROTECTED]> wrote:

> On Wed, Jun 25, 2008 at 4:08 PM, Wolf <[EMAIL PROTECTED]> wrote:
> >
> > So, where is your code that isn't working right?
>
> Yeah, come on, Thiago, show code.  You know better than that!  ;-P
>
>And by the way, I *believe* that as long as your arrays are <=
> 65,355 entries - while it will be slow and may time out - it should
> work.  So don't necessarily worry about "very long" arrays.
>
> --
> 
> Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
> $59.99/mo. with no contract!
> Dedicated servers, VPS, and hosting from $2.50/mo.
>



-- 
Thiago Henrique Pojda


Re: [PHP] array_diff()?

2008-06-25 Thread Thiago H. Pojda
Actually that was a miss when I was "translating" var names.

Here follows the code again, untouched this time:



File _pt has ~2300 lines while file _es has ~1700. Not a chance of them
having the same labels :)

On Wed, Jun 25, 2008 at 5:18 PM, Boyd, Todd M. <[EMAIL PROTECTED]> wrote:

> > -Original Message-
> > From: Thiago H. Pojda [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, June 25, 2008 3:10 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] array_diff()?
> >
> > *accidentally sent*
> >
> > Guys,
> >
> > Perhaps I'm missing something or just trying with the wrong tools...
> >
> > But the thing is, I have two arrays and want to know what values are
> in
> > one
> > that aren't in the other.
> >
> > They're very long arrays (label files for translation) and the
> > array_diff()
> > is returning null, even if I force a difference.
> >
> > What's up?
> >
> >  > $file1 = 'label_es.ini';
> > $file2 = 'label_pt.ini';
> >
> > $fh1 = fopen ($file1,'r');
> > $fh2 = fopen ($file2,'r');
> >
> > $file1 = array();
> > $file2 = array();
> >
> > while (($line = fgets($fh1))) {
> > $label = explode("=",$line);
> > $array1[] = $label[0];
> > }
> >
> > while (($line = fgets($fh2))) {
> >   $label = explode("=",$line);
> >   $array2[] = $label[0];
> > }
> >
> >
> > $missingLabels= array_diff($array1,$array2);
> >
> >
> > var_dump($labelsFaltantes); // returns nothing
> > var_dump($array1); // returns a lot of stuff
> > var_dump($array2); // returns a lot of stuff
> > ?>
>
> Umm...
>
> Is $missingLabels supposed to be what you're var_dump()ing later in the
> code? Cuz you call it $labelsFaltantes almost immediately after, which
> has not been defined (by what I can see).
>
>
> Todd Boyd
> Web Programmer
>



-- 
Thiago Henrique Pojda


Re: [PHP] array_diff()?

2008-06-25 Thread Daniel Brown
On Wed, Jun 25, 2008 at 4:08 PM, Wolf <[EMAIL PROTECTED]> wrote:
>
> So, where is your code that isn't working right?

Yeah, come on, Thiago, show code.  You know better than that!  ;-P

And by the way, I *believe* that as long as your arrays are <=
65,355 entries - while it will be slow and may time out - it should
work.  So don't necessarily worry about "very long" arrays.

-- 

Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array_diff()?

2008-06-25 Thread Boyd, Todd M.
> -Original Message-
> From: Thiago H. Pojda [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, June 25, 2008 3:10 PM
> To: php-general@lists.php.net
> Subject: [PHP] array_diff()?
> 
> *accidentally sent*
> 
> Guys,
> 
> Perhaps I'm missing something or just trying with the wrong tools...
> 
> But the thing is, I have two arrays and want to know what values are
in
> one
> that aren't in the other.
> 
> They're very long arrays (label files for translation) and the
> array_diff()
> is returning null, even if I force a difference.
> 
> What's up?
> 
>  $file1 = 'label_es.ini';
> $file2 = 'label_pt.ini';
> 
> $fh1 = fopen ($file1,'r');
> $fh2 = fopen ($file2,'r');
> 
> $file1 = array();
> $file2 = array();
> 
> while (($line = fgets($fh1))) {
> $label = explode("=",$line);
> $array1[] = $label[0];
> }
> 
> while (($line = fgets($fh2))) {
>   $label = explode("=",$line);
>   $array2[] = $label[0];
> }
> 
> 
> $missingLabels= array_diff($array1,$array2);
> 
> 
> var_dump($labelsFaltantes); // returns nothing
> var_dump($array1); // returns a lot of stuff
> var_dump($array2); // returns a lot of stuff
> ?>

Umm...

Is $missingLabels supposed to be what you're var_dump()ing later in the
code? Cuz you call it $labelsFaltantes almost immediately after, which
has not been defined (by what I can see).


Todd Boyd
Web Programmer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff()?

2008-06-25 Thread Wolf

Thiago H. Pojda wrote:

Guys,

Perhaps I'm missing something or just trying with the wrong tools...

But the thing is, I have two arrays and want to know what values are in one
that aren't in the other.

They're very long arrays (label files for translation)


You know, in the manual array_diff is an actual function...

http://us2.php.net/array

So, where is your code that isn't working right?

Wolf


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff php version

2005-06-30 Thread Richard Lynch
On Sun, June 26, 2005 2:19 am, André Le Tissier said:
> Help! Array_diff is the perfect function for what I am try to do but I
> have
> a php version 4.1.5. Is there any replacement I can use to achieve the
> same
> result

There are seven different solutions to this (with modifications of what
array_diff means) at http://php.net/array_diff

The PECL library also provides functions for forwards-compatibility, I do
believe, and I'm betting array_diff is one of them.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array_diff php version

2005-06-27 Thread Shaw, Chris - Accenture

As far as I can see in the Help File, Array_Diff was introduced in 4.0.1 and
should be in the version you are using.

Does it not work?


-Original Message-
From: André Le Tissier [mailto:[EMAIL PROTECTED]
Sent: 26 June 2005 10:20
To: php-general@lists.php.net
Subject: [PHP] array_diff php version


Help! Array_diff is the perfect function for what I am try to do but I have
a php version 4.1.5. Is there any replacement I can use to achieve the same
result



Many thanks,



André Le Tissier








This message has been delivered to the Internet by the Revenue Internet e-mail 
service

*

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff odities

2005-05-19 Thread Richard Lynch
On Wed, May 18, 2005 8:03 pm, Pablo Gosse said:
> Howdy folks.  I'm running into something strange with array_diff that
> I'm hoping someone can shed some light on.

If you are running PHP 4.0.4, the manual states that the function was
"broken"...

> I have two tab-delimited text files, and need to find the lines in the
> first that are not in the second, and vice-versa.
>
> There are 794 records in the first, and 724 in the second.
>
> Simple enough, I thought.  The following code should work:
>
> $tmpOriginalGradList = file('/path/to/graduate_list_original.txt');
> $tmpNewGradList = file('/path/to/graduate_list_new.txt');
>
> $diff1 = array_diff($tmpOriginalGradList, $tmpNewGradList);
> $diff2 = array_diff($tmpNewGradList, $tmpOriginalGradList);
>
> I expected that this would set $diff1 to have all elements of
> $tmpOriginalGradList that did not exist in $tmpNewGradList, but it
> actually contains many elements that exist in both.

Exactly what all is *IN* the records?

Phone numbers, addresses, email addresses, birthdates...

Most of which can change from year to year, and then the two records will
not print out the same, eh?

> The same is true for $diff2, in that many of its elements exist in both
> $tmpOriginalGradList and $tmpNewGradList as well.

Give us example data.

We really can't do much without data.

What are the first 10 lines of each file (change their names or whatever)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff odities

2005-05-18 Thread José Luis Palacios Vergara
-unsubscribe-digest- 
- Original Message - 
From: "Pablo Gosse" <[EMAIL PROTECTED]>
To: "PHP" 
Sent: Wednesday, May 18, 2005 11:03 PM
Subject: [PHP] array_diff odities


Howdy folks.  I'm running into something strange with array_diff that
I'm hoping someone can shed some light on.
I have two tab-delimited text files, and need to find the lines in the
first that are not in the second, and vice-versa.
There are 794 records in the first, and 724 in the second.  

Simple enough, I thought.  The following code should work:
$tmpOriginalGradList = file('/path/to/graduate_list_original.txt');
$tmpNewGradList = file('/path/to/graduate_list_new.txt');
$diff1 = array_diff($tmpOriginalGradList, $tmpNewGradList);
$diff2 = array_diff($tmpNewGradList, $tmpOriginalGradList);
I expected that this would set $diff1 to have all elements of
$tmpOriginalGradList that did not exist in $tmpNewGradList, but it
actually contains many elements that exist in both.
The same is true for $diff2, in that many of its elements exist in both
$tmpOriginalGradList and $tmpNewGradList as well.
Since this returns $diff1 as having 253 elements and $diff2 as having
183, it sort of makes sense, since the difference between those two
numbers is 70, which is the difference between the number of lines in
the two files.  But the bottom line is that both $diff1 and $diff2
contain elements common to both files, which using array_diff simply
should not be the case.
However, when I loop through each file and strip out all the tabs:
foreach ($tmpOriginalGradList as $k=>$l) {
$tmp = str_replace(chr(9), '', $l);
$tmpOriginalGradList[$k] = $tmp;
}
foreach ($tmpNewGradList as $k=>$l) {
$tmp = str_replace(chr(9), '', $l);
$tmpNewGradList[$k] = $tmp;
}
I get $diff1 as having 75 elements and $diff2 as having 5, which also
sort of makes sense since there numerically there are 70 lines
difference between the two files.
I also manually replaced the tabs and checked about 20 of the elements
in $diff1 and none were found in the new text file, and none of the 5
elements in $diff2 were found in the original text file.
However, if in the code above I replace the tabs with a space instead of
just stripping them out, then the numbers are again 253 and 183.
I'm inclined to think the second set of results is accurate, since I was
unable to find any of the 20 elements I tested in $diff1 in the new text
file, and none of the elements in $diff2 are in the original text file.
Does anyone have any idea why this is happening?  The tab-delimited
files were generated from Excel spreadsheets using the same script, so
there wouldn't be any difference in the formatting of the files.
This one has me confused as I really thought the simple code posted
above should have worked.
If anyone can pass along any advice I would greatly appreciate it.
Cheers and TIA,
Pablo
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] array_diff

2003-10-02 Thread Eugene Lee
On Thu, Oct 02, 2003 at 11:28:23AM +0200, Angelo Zanetti wrote:
: 
: I know what the problem was, firstly that when doing an array_diff the keys
: are preserved. Therefore If I was looping through $arrayResult for the count
: of elements (in this case 2) then thats where the blank value comes in. SO
: therefore if I wanted to get all the values out of the $arrayResult that are
: not blank, would I loop through the array the amount of times that there are
: elements in the $array1, because $arrayResult will be the same size as
: $array1 and also because the keys are preserved?
: 
: Im not sure if Im heading in the right direction, with regards to gettig the
: values out the $arrayResult.

How about using a foreach() automatically walk the array without having
to worry about the keys?

I wonder if there is a function to re-index an array while preserving
numerical order.  If order is not important, a sort() will re-index the
array.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array_diff [SOLVED]

2003-10-02 Thread Angelo Zanetti


-Original Message-
From: Angelo Zanetti [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 11:28 AM
To: Eugene Lee; [EMAIL PROTECTED]
Subject: RE: [PHP] array_diff


thanx Eugene,

I know what the problem was, firstly that when doing an array_diff the keys
are preserved. Therefore If I was looping through $arrayResult for the count
of elements (in this case 2) then thats where the blank value comes in. SO
therefore if I wanted to get all the values out of the $arrayResult that are
not blank, would I loop through the array the amount of times that there are
elements in the $array1, because $arrayResult will be the same size as
$array1 and also because the keys are preserved?

Im not sure if Im heading in the right direction, with regards to gettig the
values out the $arrayResult.

TIA.


-Original Message-
From: Eugene Lee [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 11:09 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] array_diff


On Thu, Oct 02, 2003 at 10:44:15AM +0200, Angelo Zanetti wrote:
:
: I am getting some weird results when using the array_diff() function.
:
: eg: $arrayResult = array_diff($array1, $array2);
:
: When i use it the resulting array ($arrayResult) gets the correct number
of
: elements, however when I echo the elements in $arrayResult it contains
some
: blank values.
:
: eg:
:
: $array1 = [123] [120] [44] [54]
: $array2 = [120] [54]
:
: then when I display $arrayResult:
: [123] ... -> blank value which should be 44.

It works for me:



with the output:

Array
(
[0] => 123
[2] => 44
)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array_diff

2003-10-02 Thread Angelo Zanetti
thanx Eugene,

I know what the problem was, firstly that when doing an array_diff the keys
are preserved. Therefore If I was looping through $arrayResult for the count
of elements (in this case 2) then thats where the blank value comes in. SO
therefore if I wanted to get all the values out of the $arrayResult that are
not blank, would I loop through the array the amount of times that there are
elements in the $array1, because $arrayResult will be the same size as
$array1 and also because the keys are preserved?

Im not sure if Im heading in the right direction, with regards to gettig the
values out the $arrayResult.

TIA.


-Original Message-
From: Eugene Lee [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 02, 2003 11:09 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] array_diff


On Thu, Oct 02, 2003 at 10:44:15AM +0200, Angelo Zanetti wrote:
:
: I am getting some weird results when using the array_diff() function.
:
: eg: $arrayResult = array_diff($array1, $array2);
:
: When i use it the resulting array ($arrayResult) gets the correct number
of
: elements, however when I echo the elements in $arrayResult it contains
some
: blank values.
:
: eg:
:
: $array1 = [123] [120] [44] [54]
: $array2 = [120] [54]
:
: then when I display $arrayResult:
: [123] ... -> blank value which should be 44.

It works for me:



with the output:

Array
(
[0] => 123
[2] => 44
)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff

2003-10-02 Thread Eugene Lee
On Thu, Oct 02, 2003 at 10:44:15AM +0200, Angelo Zanetti wrote:
: 
: I am getting some weird results when using the array_diff() function.
: 
: eg: $arrayResult = array_diff($array1, $array2);
: 
: When i use it the resulting array ($arrayResult) gets the correct number of
: elements, however when I echo the elements in $arrayResult it contains some
: blank values.
: 
: eg:
: 
: $array1 = [123] [120] [44] [54]
: $array2 = [120] [54]
: 
: then when I display $arrayResult:
: [123] ... -> blank value which should be 44.

It works for me:



with the output:

Array
(
[0] => 123
[2] => 44
)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array_diff()

2003-10-01 Thread Daniel Perez Clavero
No, but need to have same data types. You cannot compare String against
Integers and so

Regards

-Original Message-
From: Angelo Zanetti [mailto:[EMAIL PROTECTED]
Sent: miércoles, 01 de octubre de 2003 11:49
To: [EMAIL PROTECTED]
Subject: [PHP] array_diff()


HI all,

I looked at the PHP manual and it doesnt say much about this function. what
I want to know is that, do the 2 arrays have to have the same length of
number of elements?

TIA

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff()

2003-10-01 Thread Eugene Lee
On Wed, Oct 01, 2003 at 11:49:29AM +0200, Angelo Zanetti wrote:
: 
: I looked at the PHP manual and it doesnt say much about this function.
: what I want to know is that, do the 2 arrays have to have the same
: length of number of elements?

Nope.

Re-examine Example 1: $array1 and $array2 are different sizes.

http://www.php.net/manual/en/function.array-diff.php

 "green", "red", "blue", "red");
$array2 = array("b" => "green", "yellow", "red");
$result = array_diff($array1, $array2);
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array_diff usage

2001-04-02 Thread Stig Venaas

On Mon, Apr 02, 2001 at 05:15:26PM +0200, Martin Skjöldebrand wrote:
> I'm afraid I dont quite under stand the output you gave (maybe ... or do 
> you mean var_dump included the number of the array elements?)

First I echoed the number, then var_dump() also printed it, try
var_dump yourself.

Stig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array_diff usage

2001-04-02 Thread Martin Skjöldebrand

Stig Venaas wrote:

> So the arrays contain one string each? array_diff() won't work then.

Sorry - my fault.
I'm getting the values from a database - not manually added.

> Try this:
> 
> $a = array(1, 2, 3, 4, 5);
> $b = array(1, 2);
> $test = array_diff($a, $b);
> $lines = count($test);
> echo $lines;
> var_dump($test);

I'm afraid I dont quite under stand the output you gave (maybe ... or do 
you mean var_dump included the number of the array elements?)

M.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array_diff usage

2001-04-02 Thread Stig Venaas

On Mon, Apr 02, 2001 at 12:41:07AM -0700, V e r b a l wrote:
> I'm daft. I don't understand the PHP Manual.
> 
> I have two arrays:
> Open[0] contains 1 2 3 4 5
> Closed[0] contains 1 2

So the arrays contain one string each? array_diff() won't work then.
Try this:

$a = array(1, 2, 3, 4, 5);
$b = array(1, 2);
$test = array_diff($a, $b);
$lines = count($test);
echo $lines;
var_dump($test);

The output should be:

3array(3) {
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
}

Stig

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]