|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-01-18 21:05 UTC] 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!
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 09:00:01 2025 UTC |
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! ;)