Bug #74313 [Nab]: Problem from array_diff function

[email protected] ("dominik dot kolinski at gmail dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=74313&edit=1

 ID:                 74313
 User updated by:    dominik dot kolinski at gmail dot com
 Reported by:        dominik dot kolinski at gmail dot com
 Summary:            Problem from array_diff function
 Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   CentOS 7
 PHP Version:        5.6.30
 Block user comment: N
 Private report:     N

 New Comment:

Hello, Tkanka for your help help for my. This problem was due to bad types (string) for input values in my arrays. I am used function intval and problem was resolved.


Previous Comments:
------------------------------------------------------------------------
[2017-03-26 05:11:06] [email protected]

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

http://php.net/manual/en/function.array-diff.php
> ...returns the values in array1 that are not present in any of the other arrays

https://3v4l.org/OmoMT
With your sample data the function is working correctly. If $diff == $array_1 then that means $array_2 does not contain any duplicate values of $array_1, or is empty.

------------------------------------------------------------------------
[2017-03-26 00:12:22] dominik dot kolinski at gmail dot com

Description:
------------
Hello, i have a problem from array_diff function. I have a two dynamic arrays, which are a power from mysql. Which they have four different values: 4415, 4416,4417, and 4418. Unfortunately, using this feature (array_diff) has a bad output. (Return bad output)
Function returns the full contents of the first array Instead of a difference.


Please inform me what may be wrong.

Regards, Dominik Koliński.

This exemple topic in my .pl developer's forum:

http://www.elektroda.pl/rtvforum/topic3323198.html?sid=c6056d33afbbf8b9e97f904d623082f4

Array_one : 

Array
(
[0] => 4413
[1] => 4414
[2] => 13020
[3] => 13022
[4] => 4801
[5] => 4802
[6] => 4809
[7] => 11204
[8] => 14201
[9] => 14202
[10] => 14203
[11] => 12303
[12] => 12304
[13] => 10113
[14] => 10302
[15] => 10307
[16] => 4
[17] => 10404
[18] => 10502
[19] => 10701
[20] => 10704
[21] => 10801
[22] => 11006
[23] => 11201
[24] => 11305
[25] => 11310
[26] => 11605
[27] => 11702
[28] => 11705
[29] => 11707
[30] => 11803
}
And Array second:

Array
(
[0] => 4413
[1] => 4414
[2] => 13020
[3] => 13022
[4] => 4801
[5] => 4802
[6] => 4809
[7] => 11204
[8] => 14201
[9] => 14202
[10] => 14203
[11] => 12303
[12] => 12304
[13] => 10113
[14] => 10302
[15] => 10307
[16] => 4
[17] => 10404
[18] => 10502
[19] => 10701
[20] => 10704
[21] => 10801
[22] => 11006
[23] => 11201
[24] => 11305
[25] => 11310
[26] => 11605
[27] => 11702
[28] => 11705
[29] => 11707
[30] => 11803
[31] => 4415
[32] => 4416
[33] => 4417 
[34] => 4418
}

Test script:
---------------
This example from my code: 

	$query_select_id_1 = mysql_query("SELECT id FROM tabela1 where id <> 0") or die("Zapytanie niepoprawne"); 
	while($select_id_1 = mysql_fetch_assoc($query_select_id_1)){
		$array_1[] = $select_id_1['id'];
	}

	$query_select_id_2 = mysql_query("SELECT id FROM tabela2 where id <> 0") or die("Zapytanie niepoprawne"); 
	while($select_id_2 = mysql_fetch_assoc($query_select_id_2)){
		$array_2[] = $select_id_2['id'];
	}

$diff = array_diff($array_1, $array_2);
print_r($diff);



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74313&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.