Doc #77487 [Nab]: array_diff_assoc

From: Date: Fri, 18 Jan 2019 21:20:01 +0000
Subject: Doc #77487 [Nab]: array_diff_assoc
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16345@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77487&edit=1 ID: 77487 Updated by: requinix@php.net Reported by: felipegryllo at gmail dot com Summary: array_diff_assoc Status: Not a bug Type: Documentation Problem Package: *General Issues PHP Version: 5.6.40 Block user comment: N Private report: N New Comment: "are considered equal only if (string) $elem1 === (string) $elem2" Previous Comments: ------------------------------------------------------------------------ [2019-01-18 21:18:51] felipegryllo at gmail dot com Thanks for your faster anwer. But (int) 2 is not identical to (string) 2, like description says... <?php $array1 = array(0, 1, 2); // Here, 2 is integer $array2 = array("00", "01", "2"); // Here, 2 is string $result = array_diff_assoc($array1, $array2); // So, this function should return 2 print_r($result); ?> Like ((int) 2 === (string) 2) returned false... See this var_dump: var_dump($array1); /* * Return: * array(3) { * [0]=> * int(0) * [1]=> * int(1) * [2]=> * int(2) * } *************************/ var_dump($array2); /* * Return: * array(3) { * [0]=> * string(2) "00" * [1]=> * string(2) "01" * [2]=> * string(1) "2" * } *************************/ Thanks! ;) ------------------------------------------------------------------------ [2019-01-18 21:09:07] requinix@php.net ...or are you saying it should return the 2? (string)2 is "2" (string)"2" is "2" "2" === "2" is true ------------------------------------------------------------------------ [2019-01-18 21:07:42] requinix@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Now that you've read the description, read the return values section. > Returns an array containing all the values from array1 that are not present in any of the other > arrays. ------------------------------------------------------------------------ [2019-01-18 21:05:34] felipegryllo at gmail dot com Description: ------------ Hello, everyone! Please, check this description: "Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same." But this example say: <?php $array1 = array(0, 1, 2); $array2 = array("00", "01", "2"); $result = array_diff_assoc($array1, $array2); print_r($result); ?> Returns: Array ( [0] => 0 [1] => 1 ) See it: "are considered equal only if (string) $elem1 === (string) $elem2" if (2 === "2") It's false! But this function return like equals... Thanks, so mutch! ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77487&edit=1

« previous php.doc.bugs (#16345) next »